Hey PHP guys,

I am a very newbie in PHP, the only thing I know is to edit sometimes the .php files in Wordpress with the very easy tags. Anyhow.

Here's my problem.

I have this script

<a href="<?php echo get_settings('home'); ?>/"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/header.jpg" width="336" alt="<?php bloginfo('name'); ?>" /></a><br/>

This as you can see selects the header.jpg file and displays it. Now I want to put two different images in this directory, header.jpg + header2.jpg and I want a script that everytime you load a page is loading once the header.jpg and then header2.jpg and then again header.jpg etc etc. Is it possible, and since I don't know any Php can anyone of you write it for me please?
I want this for my blog http://apas.gr

It would be great if anyone of you could write that for me!

Apostolos 🙂

    <?php
    $headers = array('header.jpg', 'header2.jpg');
    $rand = array_rand($headers);
    echo '<a href="' . get_settings('home') . '"><img src="' . bloginfo('stylesheet_directory') . '/images/' . $headers[$rand] . '" width="336" alt="' . bloginfo('name') . '"></a>';
    ?>
    

      THAAAAANKS!!! 😃 😃 😃
      (soz caps it's enthusiasm! 😛)

      thanks a lot mate!!!
      I'll edit the code and if something is wrong if I'll let you know!

      again,
      1000 thanxes!!! 😃

        devinemke;10912956 wrote:
        <?php
        $headers = array('header.jpg', 'header2.jpg');
        $rand = array_rand($headers);
        echo '<a href="' . get_settings('home') . '"><img src="' . bloginfo('stylesheet_directory') . '/images/' . $headers[$rand] . '" width="336" alt="' . bloginfo('name') . '"></a>';
        ?>
        

        oops problem :$
        if you go at my blog it says

        btw the correct dir is apas.gr/wp-content/themes/upstart-blogger-theme/minim/images
        the only thing I did is added via ftp the header2.jpg onto the same dir with header.jpg and replaced the previous code I had with yours. Anything else to do or something I did wrong?

          thanks I'll check it out. But I think that I will not understand so many things. anyway, thnx I'll re post here if I need to. 🙂

            Bah. Couldn't understand most things in Matt's script. What have I to change for my situation?
            thnx

              Ok guys I finally came up with a solution. Friend of mine, http://blog.giannou.net/ did it for me.

              Here's the code

              <a href="<?php echo get_settings('home'); ?>/"><img src="<?php bloginfo('stylesheet_directory'); ?>/images/header<? echo rand(0,1); ?>.jpg" width="336" alt="<?php bloginfo('name'); ?>" /></a><br/><br/>

              And it just works.

              Thanks by the way for your help (you who posted 😃)

              cu around
              🙂

                I thought I'd mention this in case it bites you later on...

                <? echo rand(0,1); ?>

                I recommend being consistent and using "<?php" to start the block.

                  what's the difference between <php? echo rand(0,1); ?> and <? echo rand(0,1); ?>
                  ? thnx

                    Write a Reply...