• Resolved dan.tee

    (@dantee)


    Hi,

    I hope someone can help me! I’ve nearly completed a new WP site for a client (https://www.spirittosound.com) and he’s requested a slightly unusual thing. He doesn’t want the regular sidebar with search and blogroll and what not – at the moment. But he does want an image that fills the sidebar to be randomly chosen from a folder of images each time a main nav bar link is clicked.

    Everything I’ve read points to the fact that WP always refreshes the sidebar, but my site is clearly not doing this, as the sidebar only refreshes if you perform a refresh – it doesn’t do it when you use any of the links on the main nav bar.

    I’m sure this is a very simple php code drop in, but I wouldn’t even know where to drop it in, let alone how to write it. I’ve also considered just removing the side bar, and adding the image to a div on every page, but I don’t want the hassle of sorting it out again when the client wants the side bar back in the future.

    I hope I’ve made that clear enough?!

    Cheers,

    Dan

Viewing 7 replies - 16 through 22 (of 22 total)
  • If I remember it correctly, Matt’s script is specifically intended for a header image. You need a different (and probably much simpler) script altogether. Something like https://wordpress.pastebin.com/2dTDRk8H – although bear in mind that this is off the top of my head and is untested,

    Thread Starter dan.tee

    (@dantee)

    Thanks Esmi, but that script, unless I’m mistaken, will only run once on load. Then the chosen image will just sit there until the user leaves the site. They will see a new image next time the sidebar loads.

    I want the side bar to load EACH time a page link in the main nav is clicked.

    The really elegant thing about Matt’s script is that it doesn’t care how many images are in the folder, not what they’re called. This makes things much simpler for clients!

    No – if placed within the sidebar template file, it will load on every page change. I’ve used a version of this on quite a few sites.

    Thread Starter dan.tee

    (@dantee)

    OK, I’ll give it a try!

    Thread Starter dan.tee

    (@dantee)

    Nope, doesn’t work on my site. The server seems to get stuck in a loop and gives up, getting no further than a blank white page.

    And unfortunately, now I’ve removed the offending code and uploaded the original page, the site is still down. Whoops. ??

    Thread Starter dan.tee

    (@dantee)

    Phew. Thank goodness for back up, that’s all I can say. Not sure what went wrong there Esmi, but there was definitely a major problem with that code! ??

    Thread Starter dan.tee

    (@dantee)

    And finally, the solution. A friend came up with this, and it works. He suggested adding this to the img tag, straight after the rotate.php

    ?<?php echo rand(0,999); ?>

    Works a treat! Thanks for all your help and suggestions Esmi and jeFFF – much appreciated!

Viewing 7 replies - 16 through 22 (of 22 total)
  • The topic ‘Forcing the sidebar to refresh on each 'static' page link click’ is closed to new replies.