SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A Script for all Seasons

    I'm wanting the style of my site to change based on seasons.

    I have written the following code:

    <link rel="stylesheet" type="text/css" href="/style/<?php if(date(z)<33){echo("w");}else if(date(z)<125){echo("sp");}else if(date(z)<218){echo("su");}else if(date(z)<309){echo("a");}else{echo("w");} ?>.css">

    Simplified:

    PHP Code:
    if(date(z)<33){echo("w");}
    else if(
    date(z)<125){echo("sp");}
    else if(
    date(z)<218){echo("su");}
    else if(
    date(z)<309){echo("a");}
    else{echo(
    "w");} 
    I don't know--it just seems bulkier then it needs to be.

    Any ideas of a better way to do this?

    Thanks
    Last edited by samsing; Mar 24, 2006 at 19:35.

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thats about as simple as its gonna reasonably get. but you could make it more readable.

    btw- date takes a string as its argument, so use quotes, because z is not a constant.
    PHP Code:
    <?php
    $day 
    date('z');
    if(
    $day<33$season 'w';
    else if(
    $day<125$season 'sp';
    else if(
    $day<218$season 'su';
    else if(
    $day<309$season 'a';
    else 
    $season 'w';
    ?>
    <link rel="stylesheet" type="text/css" href="/style/<?php echo $season?>.css">
    you could also wrap in into a function so you could just echo get_season();


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •