A home for every day of the week
February 21, 2010 9:03 PM Subscribe
Is there some combination of PHP/JavaScript/arcane magic that'll let me change sections of a page's content based on the day of the week?
I've been coding myself a lightweight browser homepage with links to things I use every day. One thing I'd like to add to it would be a list of all the various webcomics I read, and have that list change based on which day of the week it is. Is this a pipedream, or can it be done?
I've been coding myself a lightweight browser homepage with links to things I use every day. One thing I'd like to add to it would be a list of all the various webcomics I read, and have that list change based on which day of the week it is. Is this a pipedream, or can it be done?
Best answer: You could do something like:
$filename = date('l') . ".php";
if (file_exists($filename)) {
include($filename);
} else {
include("daydefault.php");
}
Then just have a bunch of files called saturday.php, sunday.php, monday.php etc... And one called daydefault.php (optionally, for days which aren't specifically provided)
posted by sycophant at 11:16 PM on February 21, 2010
$filename = date('l') . ".php";
if (file_exists($filename)) {
include($filename);
} else {
include("daydefault.php");
}
Then just have a bunch of files called saturday.php, sunday.php, monday.php etc... And one called daydefault.php (optionally, for days which aren't specifically provided)
posted by sycophant at 11:16 PM on February 21, 2010
If you are hosting this on your computer and don't have a local server set up to run php, you can totally do it with JavaScript too. Here's a script that takes you to a different page based on the day of the week:
http://rainbow.arch.scriptmania.com/scripts/day.html
posted by beyond_pink at 5:53 AM on February 22, 2010
http://rainbow.arch.scriptmania.com/scripts/day.html
posted by beyond_pink at 5:53 AM on February 22, 2010
Response by poster: I think what sycophant mentioned is along the lines of what I'm looking for...I'll give it a shot later and report back.
posted by andrewcilento at 9:25 AM on February 22, 2010
posted by andrewcilento at 9:25 AM on February 22, 2010
Response by poster: Yep, sycophant wins. Once I realized I needed to capitalize the first letters of the day-of-the-week files, it worked beautifully.
posted by andrewcilento at 3:17 PM on February 24, 2010
posted by andrewcilento at 3:17 PM on February 24, 2010
This thread is closed to new comments.
date('w')
will return 0 through 6 depending on what day it is at the moment your script is run.date('l')
(lowercase L) will return "Sunday" through "Saturday" if you're more comfortable working with that.Use that value in a conditional statement to output the right list for the current day.
posted by wam at 9:10 PM on February 21, 2010