Random image display in Word Press

Discussion in 'Programming' started by lowprofilejoe, Aug 24, 2008.

  1. #1
    Could anyone please tell me if it's possible and how I could accomplish getting the main (header) image on a WordPress theme to randomize? I'd like to have 3 or 4 different versions of the header image appear throughout the site.

    Thanks in advance,

    Joe
     
    lowprofilejoe, Aug 24, 2008 IP
  2. megacontent

    megacontent Guest

    Messages:
    231
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Do you know what languages are available for you to use? Do you have PHP available?
     
    megacontent, Aug 25, 2008 IP
  3. eponus

    eponus Peon

    Messages:
    34
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Wordpress is PHP so he must have PHP...

    You can use a random number generator to swap out the different header images. You'll have to put this snippet in the header file of Wordpress where the header image is.

    
    <?php
        $rand = rand(0,3);
        if ($rand == 0) echo '<img src="image1.jpg">';
        if ($rand == 1) echo '<img src="image2.jpg">';
        if ($rand == 2) echo '<img src="image3.jpg">';
        if ($rand == 3) echo '<img src="image4.jpg">';
    ?>
    
    PHP:
     
    eponus, Aug 27, 2008 IP