Advanced Search

Results 1 to 2 of 2

Thread: Display an Image depending for only a specific date range.

  1. #1
    Join Date
    Jan 2009
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Display an Image depending for only a specific date range.

    I'm currently working on a project and slowly learning PHP and Wordpress. I've got the following problem that if anyone can help me with by providing me the code to learn from, I would greatly appreciate it.

    I need a specific image ("purchase_tickets_img.png") to only appear during a specific range of dates (September 20th - November 5th) using PHP. If it's not those dates, then nothing should be displayed. I need it to be a hyperlinked image, and I've got a javascript providing a roll-over effect for the image.

    Code:
    <img src="/images/purchasetickets_img.png" srcover="/images/purchasetickets_img_active.png" class="alignright" />
    Could someone be so kind as to explain / show me how the proper code to create this month based PHP scripted image that still allows it to be linked and have the roll-over effect.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    PHP Code:
    <?php
    date_default_timezone_set
    ('Europe/London'); // Change this depending on what timezone your in

    $today strtotime(date('Y-m-d'));
    $start strtotime(date('Y') . '-09-20');
    $end strtotime(date('Y') . '-11-05');

    if(
    $today >= $start && $today <= $end) { ?>
    <img src="/images/purchasetickets_img.png" srcover="/images/purchasetickets_img_active.png" class="alignright" />
    <?php
    }
    ?>
    Should do the trick. Don't know if it's the most efficient way to do it, but it works.

    Displays the image if today's date meets the conditions, otherwise shows nothing. Any link you want to add to the image, or JavaScript, can be put in between the two curly braces.

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
  •