CSS Based on Date

  • webmattster
  • Beginner
  • Beginner
  • webmattster
  • Posts: 42

Post 3+ Months Ago

Does anyone have any idea how to change the CSS on a page based on what the date is?

Thanks!
  • digitalMedia
  • a.k.a. dM
  • Genius
  • User avatar
  • Posts: 5148
  • Loc: SC-USA

Post 3+ Months Ago

I'd say use a scripting element to write the LINK tag.
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

You use PHP for that... or JavaScript... can be done in both... here is a simple PHP solution... By date I assume that you mean date as in "Monday", "Tuesday"... Why? Because the rest could be too much work...

PHP Code: [ Select ]
 
//Setting the date variable
 
$date = date(l);
 
 
 
//echo $date;
 
 
 
//The link generation (edit the HTML part to meet your CSS stylesheet name and the address)
 
if($date = 'Monday') {
 
 print '<link rel="stylesheet" href="monday.css" />';
 
} elseif($date = 'Tuesday') {
 
 print '<link rel="stylesheet" href="tuesday.css" />';
 
} elseif($date = 'Wednesday') {
 
 print '<link rel="stylesheet" href="wednesday.css" />';
 
} elseif($date = 'Thursday') {
 
 print '<link rel="stylesheet" href="thursday.css" />';
 
} elseif($date = 'Friday') {
 
 print '<link rel="stylesheet" href="friday.css" />';
 
} elseif($date = 'Saturday') {
 
 print '<link rel="stylesheet" href="saturday.css" />';
 
} elseif($date = 'Sunday') {
 
 print '<link rel="stylesheet" href="sunday.css" />';
 
} else {
 
 print '<link rel="stylesheet" href="default.css" />';
 
}
 
 
  1.  
  2. //Setting the date variable
  3.  
  4. $date = date(l);
  5.  
  6.  
  7.  
  8. //echo $date;
  9.  
  10.  
  11.  
  12. //The link generation (edit the HTML part to meet your CSS stylesheet name and the address)
  13.  
  14. if($date = 'Monday') {
  15.  
  16.  print '<link rel="stylesheet" href="monday.css" />';
  17.  
  18. } elseif($date = 'Tuesday') {
  19.  
  20.  print '<link rel="stylesheet" href="tuesday.css" />';
  21.  
  22. } elseif($date = 'Wednesday') {
  23.  
  24.  print '<link rel="stylesheet" href="wednesday.css" />';
  25.  
  26. } elseif($date = 'Thursday') {
  27.  
  28.  print '<link rel="stylesheet" href="thursday.css" />';
  29.  
  30. } elseif($date = 'Friday') {
  31.  
  32.  print '<link rel="stylesheet" href="friday.css" />';
  33.  
  34. } elseif($date = 'Saturday') {
  35.  
  36.  print '<link rel="stylesheet" href="saturday.css" />';
  37.  
  38. } elseif($date = 'Sunday') {
  39.  
  40.  print '<link rel="stylesheet" href="sunday.css" />';
  41.  
  42. } else {
  43.  
  44.  print '<link rel="stylesheet" href="default.css" />';
  45.  
  46. }
  47.  
  48.  


Hope the script works... didn't test it
  • blink182av
  • Guru
  • Guru
  • blink182av
  • Posts: 1258
  • Loc: New York

Post 3+ Months Ago

Bogey wrote:
PHP Code: [ Select ]
//Setting the date variable
$date = date(l);
 
//echo $date;
 
//The link generation (edit the HTML part to meet your CSS stylesheet name and the address)
if($date == 'Monday') {
 print '<link rel="stylesheet" type="text/css" href="monday.css" />';
} elseif($date == 'Tuesday') {
 print '<link rel="stylesheet" type="text/css" href="tuesday.css" />';
} elseif($date == 'Wednesday') {
 print '<link rel="stylesheet" type="text/css" href="wednesday.css" />';
} elseif($date == 'Thursday') {
 print '<link rel="stylesheet" type="text/css" href="thursday.css" />';
} elseif($date == 'Friday') {
 print '<link rel="stylesheet" type="text/css" href="friday.css" />';
} elseif($date == 'Saturday') {
 print '<link rel="stylesheet"  type="text/css"href="saturday.css" />';
} elseif($date == 'Sunday') {
 print '<link rel="stylesheet" type="text/css" href="sunday.css" />';
} else {
 print '<link rel="stylesheet" type="text/css" href="default.css" />';
}
 
  1. //Setting the date variable
  2. $date = date(l);
  3.  
  4. //echo $date;
  5.  
  6. //The link generation (edit the HTML part to meet your CSS stylesheet name and the address)
  7. if($date == 'Monday') {
  8.  print '<link rel="stylesheet" type="text/css" href="monday.css" />';
  9. } elseif($date == 'Tuesday') {
  10.  print '<link rel="stylesheet" type="text/css" href="tuesday.css" />';
  11. } elseif($date == 'Wednesday') {
  12.  print '<link rel="stylesheet" type="text/css" href="wednesday.css" />';
  13. } elseif($date == 'Thursday') {
  14.  print '<link rel="stylesheet" type="text/css" href="thursday.css" />';
  15. } elseif($date == 'Friday') {
  16.  print '<link rel="stylesheet" type="text/css" href="friday.css" />';
  17. } elseif($date == 'Saturday') {
  18.  print '<link rel="stylesheet"  type="text/css"href="saturday.css" />';
  19. } elseif($date == 'Sunday') {
  20.  print '<link rel="stylesheet" type="text/css" href="sunday.css" />';
  21. } else {
  22.  print '<link rel="stylesheet" type="text/css" href="default.css" />';
  23. }
  24.  


Corrected :) -- Notice the "==" instead of just "=" in the if statements and declaring the Content-type in the link.
  • joebert
  • Fart Bubbles
  • Genius
  • User avatar
  • Posts: 13504
  • Loc: Florida

Post 3+ Months Ago

Another thing you may be able to do is schedule Automated Tasks that simply rename existing CSS files.

If you tell us more about the site(s) in question, for instance what OS they're running on for starters, someone can tell you what your automation options are.
  • spork
  • Brewmaster
  • Silver Member
  • User avatar
  • Posts: 6254
  • Loc: Seattle, WA

Post 3+ Months Ago

If you're taking the PHP route, there's no need for the lengthy conditional:
PHP Code: [ Select ]
 
$date = date('l');
 
echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$date.css\" />";
 
 
  1.  
  2. $date = date('l');
  3.  
  4. echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"$date.css\" />";
  5.  
  6.  
  • Bogey
  • Genius
  • Genius
  • Bogey
  • Posts: 8416
  • Loc: USA

Post 3+ Months Ago

spork wrote:
If you're taking the PHP route, there's no need for the lengthy conditional:
PHP Code: [ Select ]
$date = date('l');
echo "<link rel="stylesheet" type="text/css" href="$date.css" />";
 
  1. $date = date('l');
  2. echo "<link rel="stylesheet" type="text/css" href="$date.css" />";
  3.  


Assuming that the stylesheet would named after the dates... (as in Monday, Tuesday...)

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 20 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.