• Hi,

    I would love to have an alternating image display in my sidebar so that each time I navigate to a new page a new image would be displayed rather than the same one across the site. Each image would be the same size and would simply replace the current one.

    Is there a widget that does this? I’ve searched but must be looking for the wrong thing.

    Thanks heaps for your help.

Viewing 5 replies - 1 through 5 (of 5 total)
  • It can be done with PHP’s conditional statement into a text widget .
    For example :

    if(pageId == 33 ){
    <img src=”url” alt=”some_text”/>
    }elseif(pageId == 38 ){
    <img src=”url-2″ alt=”some_text”/>
    }

    Hower you have to install a plugin to run PHP on WordPress post/pages .
    And to find the page/post ID read this article .

    Thread Starter dcottuli

    (@dcottuli)

    Is there a way to have a random picture appear without having to specify page id?

    Yes ofcourse , again PHP will give us the solution .
    PHP’s array_rand function is a good starting point .

    <?php
    $mypictures = array("Neo.jpg", "Morpheus.jpg", "Trinity.jpg", "Cypher.jpg", "Tank.jpg");
    $picture_to_display = array_rand($mypictures);
    echo "<img src=\"$picture_to_display\" /> " ;
    ?>

    As mentioned on my previous post , a plugin has to be installed to run PHP code in post , pages or sidebar text-widgets . I hope my over-simplified example will get you started .

    Thread Starter dcottuli

    (@dcottuli)

    On the above example kostas where would you place the images?

    Into your theme folder . For example on the twentyten theme it’s located on root-dir\wp-content\themes\twentyten\images . It all depends on the structure of you theme .

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Alternating image in sidebar’ is closed to new replies.