WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Random background image (10 posts)

  1. oval
    Member
    Posted 7 years ago #

    Hi guys, I would like to place a random background image function on my main wordpress page so that each time the user visits the blog or refreshes the page, a random background image appears on the entire page.

    I had acquired a javascript for the random bg image and tried to implement it in the header.php but I had no luck. Is there any other way I can do this? Any advice or info is appreciated.

    Best,
    Oval

  2. iscifi
    Member
    Posted 7 years ago #

    Ya I use one on my blog, not using javascript but a php script called rotate.php

    simple HTML, but adjust to what you need inside your header.php file

    <background="rotate.php">

    Matt of wordpress fame! has an example here:
    http://photomatt.net/scripts/randomimage/

    peace

  3. oval
    Member
    Posted 7 years ago #

    Dear Iscifi,

    Thank you so much for the tip! Works like a charm.

    Oval

  4. Jauhari
    Member
    Posted 6 years ago #

    I will use it too ;)

  5. Redsword
    Member
    Posted 6 years ago #

    This is great code. Simple & elegant.

    I do have one question on implementation.

    I am rotating the background image for the pages.

    However, I want to use a different random background image on the index.php and single.php templates. I am using the same code to get the image in each file

    <style type="text/css">body {
    	background-image: url(../../../images/backgrounds/rotate.php);
    }

    However, when I go from page to page my FireFox cache is loading the same background image instead of getting a new one (Internet Explorer 7 seems to load it new each time). If I <shift>+"Refresh" I get a different background each time but unless I do the force refresh each page loads with the cached background.

    Is there a good way to work around this?

    I assume I can use a different "random image" directory for each template and since I would call the random image from a different place there would not be the same one in the cache, but that seems very clunky.

    Any ideas?

  6. CowboyFrank
    Member
    Posted 6 years ago #

    I have noticed this too. Solution?

  7. MrMonte12345
    Member
    Posted 6 years ago #

    how could i do a rotating image in the header? same code?

  8. CowboyFrank
    Member
    Posted 6 years ago #

    That's what I'm using it for...

  9. Redsword
    Member
    Posted 6 years ago #

    Hi guys,

    It has been a few weeks. Does anyone have a clue on the different background on each page?

  10. Gorb Loonder
    Member
    Posted 6 years ago #

    If you insert the style tag `<style type="text/css">body {
    background-image: url(../../../images/backgrounds/rotate.php);
    }` into a text widget at the bottom of your sidebar it should reload with every page load.

Topic Closed

This topic has been closed to new replies.

About this Topic