Reply
Auto Updating Content?
Old 08-13-2008, 07:51 PM Auto Updating Content?
Novice Talker

Posts: 7
Trades: 0
I don't know if this is possible without some kind of CMS... but I'd like to be able to have a certain section of a website rotate content daily, from a pre-made list of content.

The idea is a daily devotional, and I have about 24 months worth of material to work with... is there a way to do this, and have the content change automatically?

I don't know anything about ASP... I've only worked with html, css, and javascript.
starlight is offline
Reply With Quote
View Public Profile
 
 
When You Register, These Ads Go Away!
Old 08-14-2008, 04:56 AM Re: Auto Updating Content?
Belfast_des's Avatar
Novice Talker

Posts: 5
Name: Des Smith
Trades: 0
If you have a large amount of content to work with (and its not highly sensitive) you could create a text file and use ASP to pull in the content.

http://www.w3schools.com/asp/asp_ref_textstream.asp
Belfast_des is offline
Reply With Quote
View Public Profile
 
Old 08-14-2008, 04:58 AM Re: Auto Updating Content?
Belfast_des's Avatar
Novice Talker

Posts: 5
Name: Des Smith
Trades: 0
Should clarify what I meant by large amount of content. Obviously, the best way for a large amount of content is to use a proper CMS to store and manage it but if you want to avoid that and have a very simplistic system and can generate a text file with enough content for the next week/month then you could pull in that content with ASP.
Belfast_des is offline
Reply With Quote
View Public Profile
 
Old 08-14-2008, 07:13 AM Re: Auto Updating Content?
chrishirst's Avatar
Super Moderator

Posts: 22,223
Location: Blackpool. UK
Trades: 0
for 2 years of pages a database (not necessarily a full blown CMS) would make the task a little simple but hey! Nothing like a challenge.
The only prerequisite is that all your existing pages MUST be able to run ASP code, ie: all have an extension of .asp or your server application mappings have been set to allow .htm(l) to run as ASP.

Put the text for each day in a text file, the file extension doesn't matter because were are not going to get the server to parse the file.
Use a fixed naming convention for the files yearnumber-monthnumber-daynumber.ext (eg: 01-12-25.ext would be Christmas Day) or better still a folder structure of

/text/yearnumber/monthnumber/daynumber.ext


this would look like -> /text/01/12/25.ext (01.ext ... to ... 31.ext) <- and so on through the year.
The files can have HTML code in them, it will just be streamed into the browser and rendered there.

the three functions below should be put into a file say "inc_file-funcs.asp" and included in every one of your existing pages with ->

Code:
<!--#include virtual="/path_to_file/inc_file-funcs.asp" -->

Code:
<%
const c_sRootFolder = "\text\"
const c_sFileExt = ".ext"
const c_sSeparator = "\"

function setFileName()
' get a string for the year (random number between 1 and 2) 
dim l_iYearNo : l_iYearNo =  setLeadZero(int((2-1+1)*rnd+1))
' get a string for the month
dim l_iMonthNo : l_iMonthNo = setLeadZero(month(date))
' get a string for the day
dim l_iDayNo : l_iDayNo = setLeadZero(day(date))

StreamText( l_iYearNo & c_sSeparator & l_iMonthNo & c_sSeparator & l_iDayNo & c_sFileExt)
end function

sub StreamText(p_sFileName)
' read in a file and stream it out to the browser
 
dim l_oFSO : set l_oFSO = createobject("Scripting.FileSystemObject")
dim l_oFSFile : set l_oFSFile = l_oFSO.OpenTextFile(server.mappath(c_sRootFolder & p_sFileName))
'write the file out line by line plus a line break
do until l_oFSFile.AtEndOfStream
with response
	.write (l_oFSFile.ReadLine)
	.write vbCrLf
end with
Loop
l_oFSFile.close
set l_oFSFile = nothing
set l_oFSO = nothing
end sub

function setLeadZero(p_iValue)
p_iValue = trim(cstr(p_iValue))
if len(p_iValue) = 1 then
	setLeadZero = p_iValue & "0"
end if
end function
%>
Then, wherever you need the text to appear simply put
Code:
<%setFileName()%>
on your existing page.

The three constants will need editing to suit your particular setup,

const c_sRootFolder = "\text\" is the root path to where the files are or the folder structure starts

const c_sFileExt = ".ext" obviously your chosen file extension

const c_sSeparator = "\" this is the file name separator.
If you are using the folder structure this will be the backslash.
If you are using file names then this should the character used to separate the numbers, or empty ("") if they are butted up to each other (011225.ext).

Avoid using spaces!

I originally wrote the base of this code to get around the limitations of ASP being unable to handle variable includes.
In ASP, because includes are evaluated on a first pass through the interpretor when the variables are instantiated but NOT assigned, you cannot have code like this:

dim variable: variable = "some_calculated_value"
...
...

more of the page is here
...
...
<!--#include virtual=variable -->

The only drawback is you cannot have ASP code in the file you are streaming in and have it run directly. You could of course use "eval()" and "execute()" inside the stream function on a line where there were code delimiters, should you so wish and have a masochistic approach to programming
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-14-2008, 01:01 PM Re: Auto Updating Content?
Novice Talker

Posts: 7
Trades: 0
So, Chris...

I would need to include all the formatting in each day's text file, correct? And this would just pull the contents of that text file into the page, and the CSS formatting would work as usual.

At the end of the two years, would this cycle back to the first entry again?

Thanks... I'll have to try it and see... I'm awaiting the content actually...
starlight is offline
Reply With Quote
View Public Profile
 
Old 08-16-2008, 10:48 AM Re: Auto Updating Content?
chrishirst's Avatar
Super Moderator

Posts: 22,223
Location: Blackpool. UK
Trades: 0
In the code I posted it will select year one or year two randomly on each page load.

Sequential rotation of the year can easily be added with a few extra lines of code though.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 08-16-2008, 10:53 AM Re: Auto Updating Content?
chrishirst's Avatar
Super Moderator

Posts: 22,223
Location: Blackpool. UK
Trades: 0
Quote:
I would need to include all the formatting in each day's text file, correct? And this would just pull the contents of that text file into the page, and the CSS formatting would work as usual.
Yep the include page just needs to be the section with the text on, (X)HTML code plus the CSS and any javascript events for the included section.

Stylesheets etc should be included in the parent document.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
Growing old is mandatory - Growing up is optional
Code Samples | People Counting System | Bits & Bobs
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Reply     « Reply to Auto Updating Content?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML

 



Page generated in 0.15251 seconds with 13 queries