Member Offer
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Wordpress / PHP question

Discussion in 'Website Design Forum:' started by chrismitchell, Nov 17, 2009.

  1. I have a nice interesting question for all those who know PHP and or Wordpress :)

    I am wanting to make the entire background be one image and I have some roll over options on my home page that I want to make the background change as I roll over them (if you get my drift).. anyone made anything like that before?
  2. designium

    designium Member

    OnMouseover Javascript for it? but didnt do anything like that...but if i tried i used for sure two different images and used javascript...
  3. javascript onMouseOver would be fine :) can you give me the code? :)
  4. designium

    designium Member

  5. designium

    designium Member

    or css could be better :D

    Add this css to your document...


    #img {
    width: 100px;
    height: 100px;
    background: URL("");
    #img:hover {
    background: URL("");

    And this code in your

    <div id="img"></div>
  6. that css one will definately do the trick :) cheers matey :D
  7. tbwcf

    tbwcf Active Member

    Css wouldn't be able to change this you can only effect the element in question not parent elements. You would need JavaScript il have a look this am if I have time.
  8. Hey Andy :) cheers for having a looksee too :) it seems to have half worked LOL :) I just need to force the CSS on a box and then it might work LOL :p
  9. tbwcf

    tbwcf Active Member

    what are you trying to do exactly Chris, maybe I misunderstood??

    I thought you wanted to on click or hover of a button change the background image of the body??
  10. Sunburn

    Sunburn Active Member

    just use jquery to append a class to the body tag on mouse over of a link.

    simple, and can be done in 3 lines of code :)
  11. nice one Geoff :) do you happen to have those 3 lines of code that I can use? LOL
  12. Jazajay

    Jazajay Active Member

    LOL Chris loving it.

    Right try this I'll write it off the cuff so let me know if you get an error.
    We'll use CSS and JS with the idea of just swoping out backgrounds, that way both, or multiple backgrounds are already loaded once the CSS sheet loads.

    So JavaScript, and if you want it in DOM scripting let me know I'll write it as onpage JavaScript just to save time.

    <a href="background.php?colour=blue" onclick="document.getElementsByTagName('body')[0].setAttribute('id','blue');return false" rel="nofollow">Blue design</a>

    <a href="background.php?colour=blue" onclick="document.getElementsByTagName('body')[0].setAttribute('id','red');return false" rel="nofollow">Red design</a>

    Then in the CSS


    But remember that for accessibility to create it manually so when JavaScript is not turned on load background.php and set the background that way, do you get me?
    Otherwise you will have pointless links.

    Let me know if you have problems with the above.


    Blue ~ XHTML
    Green ~ CSS
  13. Good on ya Jaz :D I'll give it a go now :D I'll be so chuffed if it works :D
  14. That worked an absolute treat :D It just needed a bit of an edit (mainly putting the onMouseOver in and making it sit in a div :D but it works :D)

    Thanks Jaz :D
  15. Ok now that's sorted..

    I have a 2nd question, now i've made the background change on the roll over, I now need to make it change to the background on the page that it changed if that makes sense?

    eg: you rollover button 1 it shows background 1, then when you click button 1 to go to post 1, with the background 1 behind it.. i'm sure that its a regular expression, but my mind is blank :p

    Cheers again :D
  16. Jazajay

    Jazajay Active Member

    Mmm.....okay the way I would do it if you are using buttons is something like this ~

    <form action="somepage.php" method="post">
    <input type="hidden" name="colour" value="red" />
    <button type="submit" onmouseover=.......></button>
    <form action="
    p" method="post">
    <input type="hidden"
    name="colour" value="blue" />
    <button type="submit" onmouseover=.......></button>

    Then test for the hidden POST variable on the next page and manually set the id of the body to which ever is set then,

    if(isset($_POST['colour']) || isset($_COOKIE['colour'])){?>
    <meta name="robots" content="noindex, follow">

    <?php if(isset($_POST['colour'])){
    setcookie("colour", $colour);

    <body id="red">

    <body id="blue">
    <?php }

    <?php }?>
    Note that is written off the cuff and may contain errors.

    Depending on how many you have you may want to convert that to a switch statement though TBH.

    As above set a cookie to test on subsequent pages and place the meta noindex on the page if the variable is present to stop duplicate content.

    Personally, not sure how your code is set up but I would change that to a link huge code reduction then.

    Sometime soon I'll do a DOM scripting post and link to it, that way you can remove the onmouseover event by pure magic. :)

    Hope it helps and let me know if it fixes it.

    Blue ~ XHTML
    Red ~ PHP

Share This Page