Fork me on GitHub

Rotating theme image  Bottom

  • Is there a way to code the theme image at the top of my site,
    http://mmdn.org/Testsite
    to rotate everytime someone visits or refreshes the site? I have about 10 different images I'd like to rotate.
    The banners function doesnt work well, it doesnt center it and has it in the upper left
  • Maybe try editing the theme so that the banner image appears where you want it. Banners is probably the easiest way to do what you want. As far as I know anyway.
  • I use a small flash app for this when my clients request it.
    You could also do it with a PHP script using the rand funtion (Don't have one handy)

    --
    Zikula Themes
  • AGlossop

    Maybe try editing the theme so that the banner image appears where you want it. Banners is probably the easiest way to do what you want. As far as I know anyway.

    That is exactly what I did at http://www.landdevelopmenttoday.com. It works great. If you visit the site, it is the image at the top right side. The client occasionally changes the images to allow for quite a bit of variation.

    Note: You might want to do some searching in the forums here. I seem to remember that someone wrote a plugin for Xanthia which would do this for you. I think it might have been InvalidResponse that did it... if IR did it, you can bet it's good stuff. :)
  • Insert this code above where the image is to be displayed in your theme.

    Code

    <?php

        // PUT EACH IMAGE INTO THE ARRAY AS SHOWN.
        // FILENAMES DO NOT MATTER SO LONG AS THEY
        // ARE VALID IMAGE NAMES
        $head_imgs = array(1=> 'image_01.jpg',
                        'image_02.jpg',
                        'image_03.jpg',
                        'image_04.jpg',
                        'image_05.jpg');

       
        // GET A RANDOM NUMBER (1 & 5 ARE INCLUSIVE...
        // CHANGE THE "5" TO THE NUMBER OF IMAGES
        // YOU'VE GOT IN THE ARRAY ABOVE
        $sel_img = rand(1,5);
       
        // HERE'S THE IMAGE TAG WITH THE RANDOM
        // IMAGE INCLUDED.  BE SURE TO CHANGE
        // THE PATH TO YOUR IMAGES.
        $use_img = '<img src="/your/img/path/'. $head_imgs[$sel_img] .'" alt="" / >';
       
        // REMOVE THIS AFTER YOU VERIFY IT WORKS
        echo $use_img;

    ?>


    To use the random image in your theme, it would be:

    Code

    <img src="/your/img/path/<?php echo $head_imgs[$sel_img]; ?>" alt="" / >


    Enjoy!
  • well i got it working sort of, is there anyway to center it and make it near the bottom grpahic?
  • Yes, any method of positioning...divs, spans, tables...will all work.
  • mt_rand() can be up to 4 times faster than rand() (depending on the system) .. also you could get a count if you didn't key the array.

    $im = array('image.gif','image2.gif','image3.gif');
    $rand = 'img';
    echo $rand;

    mmm..functions as an index.. delicious. ;)
  • I just wanted to mention about the 4 times faster...isn't it mere fractions of nanoseconds in this application?

    I didn't try it, but that's a sweet snip IR...nice... I just might have to change my approach...or at least add that technique to the ranks... Good stuff! :) I've worked on a few projects where that would be considered written a bit to "tightly" - read: too much happening in one line - but I like I like...

    :)
  • alarconcepts

    I just wanted to mention about the 4 times faster...isn't it mere fractions of nanoseconds in this application?

    haha.. well, I don't know anyone who would "knowingly" use the slower of 2 anything. you're right though, definitely.. it's just a matter of "best practices".

    alarconcepts


    I didn't try it, but that's a sweet snip IR...nice... I just might have to change my approach...or at least add that technique to the ranks... Good stuff! :) I've worked on a few projects where that would be considered written a bit to "tightly" - read: too much happening in one line - but I like I like...

    good, good.. hope it comes in handy. :)

    see ya!
  • ok, im not the brightest, how do i make it centered and looking flush with the bottom graphic. Currently it looks like http://mmdn.org/Testsite

    And the image only loads up sometimes, (keep hitting refresh)
  • The size of the image I see is a 1000px wide try scaling it to a more appropriate size for the size. What is the width of your theme?

    It didn't load for me the first time either.

    You can see how I did it on my site here

This list is based on users active over the last 60 minutes.