Jump to content

Recommended Posts

Posted

I've been searching on DynamicDrive for a script that can rotate link content.

 

Basically I'd like to feature 5-10 links on my website and have them change each day on a 7 day rotation.

 

All I found was a DHTML scroller thing, but that really isn't what I want. I'd like something static that displays 5-10 text links but that changes to a different set based on the day of the week etc.

 

Anyone have any ideas.

 

Gonna go check out HotScripts, but thought I'd post this in case someone knows of a sctipt that might work.

 

Thanks,

Nat

Posted (edited)

You could use PHP.

 

<?php

$day1 = "Saturday";

                $day2 = "Sunday";

                $day3 = "Monday";

                $day4 = "Tuesday";

                $day5 = "Wednesday";

                $day6 = "Thursday";

                $day7 = "Friday";

                $weekday = date("l");

if ($weekday == $day1) { include( $_SERVER['DOCUMENT_ROOT']."/sat.html");}

if ($weekday == $day2) { include ($_SERVER['DOCUMENT_ROOT']."/sun.html");}

if ($weekday == $day3) { include ($_SERVER['DOCUMENT_ROOT']."/mon.html");}

if ($weekday == $day4) { include ($_SERVER['DOCUMENT_ROOT']."/tues.html");}

if ($weekday == $day5) { include ($_SERVER['DOCUMENT_ROOT']."/wed.html");}

if ($weekday == $day6) { include ($_SERVER['DOCUMENT_ROOT']."/thurs.html");}

if ($weekday == $day7) { include ($_SERVER['DOCUMENT_ROOT']."/fri.html");}

?>

 

Create 7 HTML files with the content to appear for that day of the week. Then insert this PHP script in your page where you want the content to appear.

 

I've modified this per TCH-Andy's post below for compactness. :P

Edited by TCH-Bruce
Posted

Bruce! You are my hero!

 

That is exactly what I was looking for.

 

Now I must go smack myself up the head for not being more diligent in learning PHP.

 

So much to do... so little time. LOL

 

Thanks a million,

 

Nat

Posted

i was looking for something similiar but am unable to work out what to do exactly, basically i have a list of text links on a page and i want them to rotate so to speak every now and again so that they each get a turn as the first link.

 

do you understand or am i talking gibberish.

 

example

 

mayfair hotel

oren hotel

castle hotel

 

becomes

 

oren hotel

castle hotel

mayfair hotel

 

when someone else goes into the page and so on so they all get a turn as the first link

Posted
Glad I could help.  :oops:

 

Bruce,

 

OK just finished the htm pages and popped the PHP code into my page. For some reason the links aren't showing up. www.natalie-brown.com. All that you see are the Horizontal rules.

 

Here is my code:

 

>$day1 = "Saturday";
               $day2 = "Sunday";
               $day3 = "Monday";
               $day4 = "Tuesday";
               $day5 = "Wednesday";
               $day6 = "Thursday";
               $day7 = "Friday";
               $weekday = date("l");
if (($weekday == $day1) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/sat.htm";
               }
if (($weekday == $day2) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/sun.htm";
               }
if (($weekday == $day3) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/mon.htm";
               }
if (($weekday == $day4) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/tues.htm";
               }
if (($weekday == $day5) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/wed.htm";
               }
if (($weekday == $day6) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/thurs.htm";
               }
if (($weekday == $day7) {
   include "$_SERVER['DOCUMENT_ROOT']."http://www.natalie-brown.com/content/fri.htm";
               }

 

Did I write the links to the seperate pages wrong? I put all those pages in a "content" folder on my site.

 

I tested the page on Firefox and IE 6.

 

Hmmmm what did I do wrong?

 

Nat

Posted

Nat, you didn't need to change any of the links unless you changed the HTML doc names or the pages are not in the same folder as the page they are being displayed on.

 

The "$_SERVER['DOCUMENT_ROOT']." is the path to the page. Remove the http://www.natalie-brown.com and it should work.

 

If you have the pages in a "content" folder then make the link part "/content/mon.htm" and it should work.

 

If the pages are in the same folder as the page they are to be viewd on then remove the "/content" as well.

Posted
Nat, you didn't need to change any of the links unless you changed the HTML doc names or the pages are not in the same folder as the page they are being displayed on. 

 

The "$_SERVER['DOCUMENT_ROOT']." is the path to the page. Remove the http://www.natalie-brown.com and it should work.

 

If you have the pages in a "content" folder then make the link part "/content/mon.htm" and it should work.

 

If the pages are in the same folder as the page they are to be viewd on then remove the "/content" as well.

 

 

Bruce,

 

The pages are all in a /content folder on the site. I did change the links to remove the http://www.natalie-brown part, but the links still aren't showing. The whole content folder is uploaded.

 

You can do a view source to see the entire code for the index page if that helps. Here is the ammended code:

 

>$day1 = "Saturday";
               $day2 = "Sunday";
               $day3 = "Monday";
               $day4 = "Tuesday";
               $day5 = "Wednesday";
               $day6 = "Thursday";
               $day7 = "Friday";
               $weekday = date("l");
if (($weekday == $day1) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/sat.htm";
               }
if (($weekday == $day2) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/sun.htm";
               }
if (($weekday == $day3) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/mon.htm";
               }
if (($weekday == $day4) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/tues.htm";
               }
if (($weekday == $day5) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/wed.htm";
               }
if (($weekday == $day6) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/thurs.htm";
               }
if (($weekday == $day7) {
   include "$_SERVER['DOCUMENT_ROOT']."/content/fri.htm";
               }

 

Not sure what I did wrong... I know it must be something simple. LOL it always is!

 

Thanks for the help.

 

Nat

Posted

Where in your directory tree is the page you want it on and where in the directory tree are the mon-fri.htm files?

 

Is everything in /content? Is /content in your public_html folder?

 

Sorry, need to know these things to answer properly.

Posted

Nat, I looked at your thurs.htm page.... It's a full HTML page...

 

The only content that should be in these day pages should be the the stuff between the

and tags. Just the link information.

 

The style will come from the CSS of the page it appears on.

 

And the links should work if coded like this...

 

include "$_SERVER 'DOCUMENT_ROOT']."/content/????.htm";

Posted

And if the page you are using this on is not a PHP page you will need to be sure that the following is in your .htaccess file.

 

AddType application/x-httpd-php .htm .html

Posted
Where in your directory tree is the page you want it on and where in the directory tree are the mon-fri.htm files?

 

The page I want the links on is my index.htm page. That page is in the main folder. The public_html one.

 

Is everything in /content?  Is /content in your public_html folder?

All the daily rotation pages are in /content. The /content folder is in the public_html one. So it looks like:

>public_html folder

-index.htm

>content folder

-all sun-mon.htm pages reside in the content folder

 

Nat, I looked at your thurs.htm page.... It's a full HTML page...

 

Ah yes, they are all full HTML pages.

So you are saying delete everything that is not within the <body> tags? Like this?

><body>
Listen to Natalie's Music @</font></b></b> <a href="http://www.acidplanet.com/artist.asp?AID=160199&T=92430" target="_blank">Acidplanet</a> | <a href="http://www.amazon.com/exec/obidos/tg/stores/artist/-/digital-music/219777/103-4337476-5724600" target="_blank">Amazon Pop</a> | <a href="http://www.amazon.com/exec/obidos/tg/stores/artist/-/digital-music/215749/103-4337476-5724600" target="_blank">Amazon Urban</a> | <a href="http://www.amazon.com/exec/obidos/tg/stores/artist/-/digital-music/240906/103-4337476-5724600" target="_blank">Amazon General</a> | <a href="http://artistgigs.com/artist.pl?id=1052" target="_blank">Artist Gigs</a> |<br> 
| <a href="http://www.artistlaunch.com/artist4.asp?artistid=334" target="_blank">Artistlaunch</a> | <a href="http://www.artistnow.com/index.php?m=vp&a=1&id=15619" target="_blank">Artistnow</a>  | <a href="http://www.audiostreet.net/artists/002/630/natalie_brown.html" target="_blank">Audiostreet</a> | <a href="http://www.beatmaka.com/natalie_brown" target="_blank">Beatmaka</a> | <a href="http://www.belgiummp3.be/mp3/Natalie_Brown/" target="_blank">Belgium Mp3</a> | <br>
| <a href="http://www.bitchinentertainment.com/natbrownepk.html" target="_blank">Bitchin' Entertainment</a> | <a href="http://www.bigtalent.com/cgi-bin/bigtalent/browse?category=55&user=1428" target="_blank">Big Talent</a> | <a href="http://www.broadjam.com/artistprofile/artistindex.asp?artistID=773" target="_blank">Broadjam</a> | <a href="http://newmusic.clearchannel.com/artist/nataliebrown" target="_blank">New Music Network</a> | <a href="http://www.download.com/nataliebrown" target="_blank">CNET</a>
</body>

 

The style will come from the CSS of the page it appears on.

The CSS is not a global CSS page. It's all formated in Dreamweaver. I haven't yet changed my main site to a global CSS type format.

 

The only content that should be in these day pages should be the the stuff between the <body> and </body> tags. Just the link information.

 

And the links should work if coded like this...

 

include "$_SERVER 'DOCUMENT_ROOT']."/content/????.htm";

Right now the code I have on the index.htm page for the include is:

>include "$_SERVER['DOCUMENT_ROOT']."/content/fri.htm";

 

I should change that to take out the "["?

 

And if the page you are using this on is not a PHP page you will need to be sure that the following is in your .htaccess file.

 

AddType application/x-httpd-php .htm .html

Oh lord! I've never changed the .htaccess file. Do I do that through CPanel and where do I put that line? Not sure how to change that file.

 

Thanks a million Bruce. I'm learning a ton :notworthy:

Posted

Bruce,

 

Just looking at my htaccess file and it says the following:

# -FrontPage-

 

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

 

<Limit GET POST>

order deny,allow

deny from all

allow from all

</Limit>

<Limit PUT DELETE>

order deny,allow

deny from all

</Limit>

AuthName www.natalie-brown.com

AuthUserFile /home/natalie/public_html/_vti_pvt/service.pwd

AuthGroupFile /home/natalie/public_html/_vti_pvt/service.grp

I added the line you suggested:
AddType application/x-httpd-php .htm .html
to the bottom line on the htaccess file but when I overwrote the old htaccess file, my web site went 'blank'. I deleted the line and changed the file back to what it was originally.

 

Where do I put that line of code in the htaccess file?

 

Thanks,

Nat

Posted

I can't for the life of me figure out why it's not working.

 

The update to your .htaccess file should work anywhere in there. I added mine to the top on one site and bottom on another. Both work. I assume you had a backup of your .htaccess file before you changed it.

 

As for your mon-fri.htm pages, there should be no

tags either.

 

If the include path isn't working try this:

 

include "/home/yourcpanelname/public_html/content/mon-fri.htm" ;

 

It should work. Or you can go with the original links I gave if you put the mon-fri-htm files in your public_html folder.

Posted

OK I am going to put the files from the content folder in my public_html file. I deleted the body tags. Hang on and I'll let you know when I've uploaded them.

Posted

Ok I did it but it just shows this:

?>

 

Do I still need to change the htaccess file if I go with the original code and putting the rotating content pages in the public_html folder?

 

I have no idea why my site freaked out when I added that line. Strange.

Posted

Nat you have this in your index page.

 

         
          <?php<?php

$day1 = "Saturday";

                $day2 = "Sunday";

                $day3 = "Monday";

                $day4 = "Tuesday";

                $day5 = "Wednesday";

                $day6 = "Thursday";

                $day7 = "Friday";

                $weekday = date("l");

if (($weekday == $day1) {

    include "$_SERVER['DOCUMENT_ROOT']."/sat.html";

                }

if (($weekday == $day2) {

    include "$_SERVER['DOCUMENT_ROOT']."/sun.html";

                }

if (($weekday == $day3) {

    include "$_SERVER['DOCUMENT_ROOT']."/mon.html";

                }

if (($weekday == $day4) {

    include "$_SERVER['DOCUMENT_ROOT']."/tues.html";

                }

if (($weekday == $day5) {

    include "$_SERVER['DOCUMENT_ROOT']."/wed.html";

                }

if (($weekday == $day6) {

    include "$_SERVER['DOCUMENT_ROOT']."/thurs.html";

                }

if (($weekday == $day7) {

    include "$_SERVER['DOCUMENT_ROOT']."/fri.html";

                }

?>

?>           


 

Remove the parts that I have bolded in red.

Posted
Yes, since your pages end in .html or .htm you need this line in your .htaccess file.

 

AddType application/x-httpd-php .htm .html

 

OK I will try it again.

 

What I had done is downloaded to my desktop it using SmartFTP, i opened it up in WordPad, added the line and then overwrote the htaccess file.

 

Is that the right way to do it?

 

Nat

Posted

OK I also removed the extra lines that were messing up the code, as you bolded in red.

Posted (edited)
Yes, since your pages end in .html or .htm you need this line in your .htaccess file.

 

AddType application/x-httpd-php .htm .html

 

OK I will try it again.

 

What I had done is downloaded to my desktop it using SmartFTP, i opened it up in WordPad, added the line and then overwrote the htaccess file.

 

Is that the right way to do it?

 

Nat

 

Save a copy to your machine and then edit the file on the server using File Manager in cPanel. That's how I do it and it always works. :)

Edited by TCH-Bruce
Posted

Ok I had forgotten to delete the "l" to change the url to an htm file.

 

I changed that, but it still doesn't seem to work.

 

I am just headed out and will be back later to try to get to the bottom of this.

 

Feel free to view source if that helps any.

 

Sorry this is proving to be a bear! lol

 

Nat

Posted

Strangely enough I just looked at the hataccess file again and whatever I changed is now gone?

 

Why would it revert back to the old file? I used the "Edit File" function.

Posted

Ok so strange... I went and added the line to the htaccess file and then saved it. I refreshed my site and it went blank again.

 

Here is how the hataccess file looks in cPanel

>.htaccess
File Type: ASCII text

# -FrontPage-

IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*


order deny,allow
deny from all
allow from all


order deny,allow
deny from all

AuthName www.natalie-brown.com
AuthUserFile /home/natalie/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/natalie/public_html/_vti_pvt/service.grp
AddType application/x-httpd-php .htm .html

Posted

Argh... yup the site is blank. I will have to delete that line to make the site show again.

 

Why is adding that line making things go blank?

 

OK i have to jet... let me get back online later today.

 

This is so strange huh!

Posted

The site is blank, because it is now trying to interpret the PHP.

 

However I think there is an error in the PHP - the brackets don't tie up :)

 

I would rename a copy of index.htm to test.php - remove the line in the .htaccess for now - and then test the php part.

Posted

Nat, the following will work. I have downloaded you index file and edited to test.

 

<?php

      $day1 = "Saturday";

      $day2 = "Sunday";

      $day3 = "Monday";

      $day4 = "Tuesday";

      $day5 = "Wednesday";

      $day6 = "Thursday";

      $day7 = "Friday";

      $weekday = date("l");

if ($weekday == $day1) {

    include "/home/yourcpanelname/public_html/sat.htm";

}

if ($weekday == $day2) {

    include "/home/yourcpanelname/public_html/sun.htm";

}

if ($weekday == $day3) {

    include "/home/yourcpanelname/public_html/mon.htm";

}

if ($weekday == $day4) {

    include "/home/yourcpanelname/public_html/tues.htm";

}

if ($weekday == $day5) {

    include "/home/yourcpanelname/public_html/wed.htm";

}

if ($weekday == $day6) {

    include "/home/yourcpanelname/public_html/thurs.htm";

}

if ($weekday == $day7) {

    include "/home/yourcpanelname/public_html/fri.htm";

}

?>

 

Replace yourcpanelname with your cpanel name. Also, in your mon-fri.htm pages you will have to add your font size tags otherwise they will appear larger than the other links.

 

Let me know if you still have problems.

Posted

Try;

 

>if ($weekday == $day1) {    include( $_SERVER['DOCUMENT_ROOT']."/sat.html");}
if ($weekday == $day2) {    include ($_SERVER['DOCUMENT_ROOT']."/sun.html");}
if ($weekday == $day3) {    include ($_SERVER['DOCUMENT_ROOT']."/mon.html");}
if ($weekday == $day4) {    include ($_SERVER['DOCUMENT_ROOT']."/tues.html");}
if ($weekday == $day5) {    include ($_SERVER['DOCUMENT_ROOT']."/wed.html");}
if ($weekday == $day6) {    include ($_SERVER['DOCUMENT_ROOT']."/thurs.html");}
if ($weekday == $day7) {    include ($_SERVER['DOCUMENT_ROOT']."/fri.html");}

 

Hopefully I have all the quotes and brackets in the right places - let me know if not

Posted (edited)

Andy, that would probably work too. I edited her page as a test and posted how I did it above yours and it works. :)

 

Andy, I tested your "if" statements and they also work except for the page names. The are .htm and not .html

 

Thanks for the edit! :)

Edited by TCH-Bruce
Posted

Ok so do I use what Andy wrote or what Bruce wrote and where do I put it in the page? Do I write over that original code that Bruce wrote?

 

Should I change the page to index.php and if I do that, what is the best way? I wonder if everyone can see PHP on even old browsers?

 

Do I still need to change my htaccess file?

 

Thanks guys, what a blessing you are!

 

Nat

Posted
Nat, the following will work.  I have downloaded you index file and edited to test.

 

<?php

      $day1 = "Saturday";

      $day2 = "Sunday";

      $day3 = "Monday";

      $day4 = "Tuesday";

      $day5 = "Wednesday";

      $day6 = "Thursday";

      $day7 = "Friday";

      $weekday = date("l");

if ($weekday == $day1) {

    include "/home/yourcpanelname/public_html/sat.htm";

}

if ($weekday == $day2) {

    include "/home/yourcpanelname/public_html/sun.htm";

}

if ($weekday == $day3) {

    include "/home/yourcpanelname/public_html/mon.htm";

}

if ($weekday == $day4) {

    include "/home/yourcpanelname/public_html/tues.htm";

}

if ($weekday == $day5) {

    include "/home/yourcpanelname/public_html/wed.htm";

}

if ($weekday == $day6) {

    include "/home/yourcpanelname/public_html/thurs.htm";

}

if ($weekday == $day7) {

    include "/home/yourcpanelname/public_html/fri.htm";

}

?>

 

Replace yourcpanelname with your cpanel name. Also, in your mon-fri.htm pages you will have to add your font size tags otherwise they will appear larger than the other links.

 

Let me know if you still have problems.

 

 

Bruce,

 

I added in the code as you specified and put in my cPanel username where you indicated.

 

I checked the page and the links are still not showing.

 

If I used what Andy wrote, where would I put it and in what format?

 

Nat

Posted
The site is blank, because it is now trying to interpret the PHP.

 

However I think there is an error in the PHP - the brackets don't tie up :(

 

I would rename a copy of index.htm to test.php - remove the line in the .htaccess for now - and then test the php part.

 

Where is the bracket error?

 

I will try to rename the file to PHP and test it.

 

Do I have to remove all that beginning HTML part if I rename the file to a PHP file?

 

Thanks,

Nat

 

PS will work on this during the week.... just off to bed now.

Posted

YAY!

 

Got it to work :wallbash:

 

Thank you Bruce and Andy for all your help in getting this working.

 

It's PURRRR-FECT!

 

Hugs,

Nat

Posted

For brevity and more flexibility going forward:

 

><?php
$file_ar = array('fileSun.htm', 'fileMon.htm', 'fileTue.htm', 'fileWed.htm', 'fileThur.htm', 'fileFri.htm', 'fileSat.htm');
$weekday = date("w");/* 0=Sunday */
if(isset($file_ar[$weekday]) && $file_ar[$weekday] != '')
{
include( $_SERVER['DOCUMENT_ROOT'].'/'.$file_ar[$weekday];
}

?>

  • 2 months later...
Posted

Hi Bruce.

 

Thank you for posting the PHP code for rotating content. I've found it VERY useful.

 

I'm new to PHP code, but couldn't this script be condensed even further to just:

 

<?php

$day = (date("D"));

include("($_SERVER['DOCUMENT_ROOT']."/$day.html");

?>

 

(assuming the .html files are named mon.html, tues.html, wed.html, etc.)

 

~Marty

Posted
<?php

$day = (date("D"));

include("($_SERVER['DOCUMENT_ROOT']."/$day.html");

?>

 

(assuming the .html files are named mon.html, tues.html, wed.html, etc.) 

 

I had to make a minor change for it to work for me:

><?php
$day = (date("D"));
include $_SERVER['DOCUMENT_ROOT']."/$day.html";
?>

And it assumes the .html files are named Mon.html, Tues.html, etc.

Posted (edited)
This daily rotating php script, is there some way I can make it weekly instead, so the content are changed every monday? :D

The PHP code for "week number of the year" is W, and it starts on Monday. I haven't tested it yet but I imagine this would work:

><?php
$week = (date("W"));
include("($_SERVER['DOCUMENT_ROOT']."/$week.html");
?>

You could create the weekly pages in advance, and when that Monday rolls around, voila.

 

BTW, for more date codes, go here.

Edited by timhodge
Posted

I haven´t tried this yet, so maybe the answer is in there , but I thought of something...

If I use the code

><?php
$week = (date("W"));
include("($_SERVER['DOCUMENT_ROOT']."/$week.html");
?>

How does the server know when its time to show a new "made in advance" htmlpage?

 

As I understand it, I either have to upload a week.html every monday or change $week.html to $week1.html $week2.html and so on every week.

Am I correct or wrong?

Posted
I haven´t tried this yet, so maybe the answer is in there , but I thought of something...

If I use the code

><?php
$week = (date("W"));
include("($_SERVER['DOCUMENT_ROOT']."/$week.html");
?>

How does the server know when its time to show a new "made in advance" htmlpage?

 

As I understand it, I either have to upload a week.html every monday or change $week.html to $week1.html $week2.html and so on every week.

Am I correct or wrong?

 

Wrong. $week is a variable defined by the date() function. We are saying that $week will equal the number of whatever week in the year it is, somewhere between 1 and 52. You will create a file for each week number. So right now we are wrapping up week 9. For tomorrow, have a file called 10.html ready to go. For next Monday, use 11.html. And so on. Make sense?

Posted
since you all are sharing efficiency tips...

 

how about this..if you're only including html/text and not php...don't use include...use file_get_contents...its waaaaaaaaaaay faster and more efficent.

 

I just made this bechmark script just for you guys...Observe and comment!!!

http://section31.us/test/includeVsfile_get_contents.php

Neat. I'll have to put that in my bag of tricks.

 

-Tim

Posted
Nice tip!

A Google search for "file_get_contents include performance" found me this interesting page about a comparisson of various methods to include static content with PHP. Looks like fpassthru is an even faster alternative.

 

WOAH.... Good find..

 

I've now added the other functions to my test and have increased the file to 220KB...

 

Check out the results...

 

http://section31.us/test/includeVsfile_get_contents.php

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...