Change Logo Based On Date?

Discussion in 'HTML & Website Design' started by bschneider5, Dec 24, 2006.

  1. #1
    I own a VBulletin Forums in which I'd like the header image to change based on certain dates. (So my christmas logo will come up on the 16th, etc). I would like this to happen without having to go in and edit code every time. Anyone know how to pull this off?
     
    bschneider5, Dec 24, 2006 IP
  2. fsmedia

    fsmedia Prominent Member

    Messages:
    5,163
    Likes Received:
    262
    Best Answers:
    0
    Trophy Points:
    390
    #2
    you could just need to use some php and the date() function to determine the current date and then use an if else statement so if ( Date = this time - that time ) { display this image } else { display the original image }

    Someone else should be able to create the exact PHP for it, but that's the idea...
     
    fsmedia, Dec 24, 2006 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #3
    Try this code:
    (Assuming your images are stored in a folder called "images", 1 directory below where the code is executed.)
    <?php
    $mdarr= "18-25/12,13-20/05";
    $miarr= "christmas.jpg,happy_birthday_jeet.jpg";
    // Format explained below and why use this.

    $jtd= date("d");
    $jtd= $jtd-7;// Minus 7 days to match above format.
    $jtd= $jtd . '-'. date("d"). '/' . date("m");
    $jc=0;
    $r= explode(",",$mdarr);
    foreach($r as $v)
    {
    if($jtd==$v)
    {
    ++$jc;
    }
    }
    if($jc>0)
    {
    --$jc;
    $img= explode(",", $miarr);
    $img= $img[$jc];
    print '
    <img src="images/'. $img. '" alt="'. $img. '" />
    ';
    }
    else
    {
    print '
    <img src="images/default_logo.jpg" alt="default logo" />
    ';
    }
    ?>

    About the date format.

    $mdarr= "18-25/12,13-20/05";
    Here you can fit an array for all the dates you wish to change your image on.
    For example 25/12 (25 December.) Minus 7 days makes it:
    18-25/12, so your image starts appearing 7 days before the actual festival.
    Add a "," sign and enter another date in same format.
    (Minus 7 days)-(Actual date)/(month)
    Add as many as you like.

    Which Image to use:
    $miarr= "christmas.jpg,happy_birthday_jeet.jpg";

    Just enter the full image file name for each date at the same "number" position as it appears in date array.
    Seperated by "," sign.

    18-25/12 was first item, so "christmas.jpg" is first in this array.
    and so on.

    Then replace the <img tag for your logo with this code above.
    Fill the array once, and probably will never have to touch it again...
    Bye :)
     
    JEET, Dec 24, 2006 IP
    bschneider5 likes this.
  4. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #4
    Thanks Jeet, a link in my blog and green rep. Thanks!
     
    bschneider5, Dec 24, 2006 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,832
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #5
    Hi,
    Thanks for the link and rep.
    Take a look at your blog. Towards the end of the post.
    The line where I said:
    "Then replace the <img tag..."
    The <img tag is getting displayed as html...
    Might wanna fix it.
    Bye :)

     
    JEET, Dec 24, 2006 IP
  6. bschneider5

    bschneider5 Active Member

    Messages:
    1,009
    Likes Received:
    44
    Best Answers:
    0
    Trophy Points:
    88
    #6
    OK got it, thanks!
     
    bschneider5, Dec 24, 2006 IP