Forum Moderators: open

Message Too Old, No Replies

Daily Fact

javascript for search engine friendly daily fact

         

gckorn

3:53 pm on Jun 16, 2008 (gmt 0)

10+ Year Member



I've been asked to take over a Daily Fact file from another website. I have 2 1/2 different .txt files for this (i.e., a complete set of facts for 365 days; a second different complete set; and a 3rd partial set).

I would like to take these sets - at least the 2 complete sets - and put them into a file (or files) that are search engine friendly, and then have javascript to "play" them each day.

From an old thread, I saw that this can be done, but I am not a code so I'm not sure how. There is reference to using the following:

"As a first step I would include all the facts into page with only one visible something like
<span id='fact1' >Blah blah .. </span>
<span id='fact2' class='hideme'>Blah blah .. </span>
etc, with suitable css entry for 'hideme' ... this way search engines will see all your facts. The job of the javascript is then to change the className of the choosen one to "" and the rest to "hideme"

However, I don't know the javascript. I'm also not quite sure how to properly alter the .txt file per the suggestion above.

Appreciate any help!
Thanks,
gckorn

daveVk

5:18 am on Jun 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What do have in mind with the 2.5 sets, a 2.5 year cycle, 2.5 per day ?

You could hand convert the txt files into html pages, but better if you have access to PHP or some other server side scripting support, this needs to be done on the server side for the search engines to index it.

There is not much javascript involved, lets know when you have requirements sorted out.

gckorn

11:44 am on Jun 17, 2008 (gmt 0)

10+ Year Member



Hi Dave,

Thanks for your reply. The cycle I have in mind is this (essentially a 2 1/2 year cycle):

2008 - Run B.txt (which has items for all 365 days)
2009 - Run C.txt (ditto)
2010 - Run B.txt (except the period June 18 through December 31, which runs A.txt which I will expand.

2011 - Run B.txt
2012 - Run C.txt
2013 - Run A.txt (fully expanded by then)

I have PHP server side scripting available, though I'm not sure how to code the PHP. That's pretty much it. Can you help?

Thank you in advance,
Gary

Dabrowski

1:24 pm on Jun 17, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What I have is a list of "On This Day in Maine" stuff. So June 17 has a factotum relating to that date. I would need to show the June 17 fact on June 17, then the June 18 fact on June 18, etc.

First, in your text file, I would start each article with a datestamp. To convincingly put these in HTML I would divide them up monthly, that way you have quite a few pages of good content for the search engines, and it's also usable if your users decide to browse the pages.

Second, if your site is in HTML, I would take advantage of SHTMLs' #include directive to insert your 'on this day' article in the page, which could point to a simple script, written in PHP, Perl, whatever that could easily pick up the correct article, while maintaining the yearly cycle without having to change something once per year (think %3).

daveVk

2:40 am on Jun 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please post some sample lines from one of the text files to show formating etc. Do the facts include links or other formating ?

To keep it simple perhaps put 1 year file on server and update it annually ?

gckorn

11:07 am on Jun 18, 2008 (gmt 0)

10+ Year Member



Thank you all. The following code - all php - works and is currently running. Format for .txt file is, e.g., July¦1¦Textual Information.

<?php

$file = file('data.txt');
$today = getdate();

foreach ($file as $line => $data)
{
list($month, $day, $tip) = explode('¦', trim($data) );

if ($today['month'] == $month AND $today['mday'] == $day)
{

echo $tip;
echo "<p>";
}
}

?>

gc

Dabrowski

9:07 pm on Jun 18, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is fantastic, exactly what I was getting at!

To make it even more maintenance free, you can use the mod operator to cycle the correct year.

For example (and I'm writing generally here, I don't do PHP but I'll assume it will work):

filenumber = ((year -2008) % 3) +2008

year -2008 will start at 0 for this year. %3 will 'loop' every 3 years, so you'll get 0, 1, 2, 0, 1, 2, etc.... By adding 2008 on again you'll get year numbers, 2008, 2009, 2010, 2008, 2009, 2010, etc....

So you can call your files by a name like 'year2008.txt' and onwards, so you'll never need to modify the script to adjust for different years, at least until you add more facts.