Support » Plugins » Hacks » Forcing the sidebar to refresh on each 'static' page link click

  • Resolved dan.tee



    I hope someone can help me! I’ve nearly completed a new WP site for a client ( 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?!



Viewing 15 replies - 1 through 15 (of 22 total)
  • Hello,

    Quick question, did you use the widgets for your website ?
    You can achieve what you want by creating a specific widget wich will get a random picture quite easily.
    Let me know if it’s what you want.


    Hi JeFFF

    Thanks for having a look. I’ve searched for plugins that do this job and couldn’t find anything suitable. I think the real issue is that whatever is in the sidebar that swaps images needs to know when the page links are clicked and then perform a reload and thus a new image. That seems to be the problem.

    Just how did you put the current pictures ?
    Multiple sidebars definition ?

    Currently the images are in [theme]/images/sidebar. The code I’m using is Matt Mullenweg’s image rotator. It consists of an php file called ‘rotate.php’ that lives in the sidebar images folder. To use it, you just add rotate.php to the img src tag.

    The rotate works just fine – when the sidebar loads for the first time, it chooses an image and loads it in the side bar. But when you subsequently click on, say, ‘showreel’ it doesn’t refresh the image. That’s what I’m after.

    It works perfectly on my browser actually, each page display a new picture.

    It may be just a cache issue, try to add these lines :

    header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
    header("Expires: Sat, 26 Jul 1997 05:00:00 GMT");

    just before this one :
    header('Location: '.$folder.$files[$rand]);

    It will override the cache.

    Hope this will help

    Thanks for the code snippet – I’ve put it in, and it’s made no difference for me, on my browser: Safari 5.0.3, OS X 10.6.4 My client is also using the same computer type and set up and it hasn’t been working for him either.

    The other slightly odd thing is that I’m only seeing your replies in my email, not on the forum itself – what’s that about? 🙂

    Same for me …. I don’t understand why !
    I only see my replies when I’m connected !

    The forum at least is working properly now! Any other ideas as to how I can solve my refresh problem?

    I put the code snippet into rotate.php – is that where you meant me to put it?



    Forum Moderator

    The forum was working properly before. It operates anti-spam measures and some replies may end up caught in the spam queue. These are released at regular intervals throughout the day.

    ahh, that explains it then. Have you got any ideas how to fix my refresh problem? 😉



    Forum Moderator

    My guess is that you need to replace your rotate.php script with something that is more suited to a sidebar rather than a header image.

    got all excited there for a second jeFFF, when I finally saw your actual code snippet here on the forum – you’d used double quotes, not single quotes as I assumed they would be when all I could see was the garbage that showed up in the forum email that I received. So I copied and pasted with the single quotes but no joy.

    Anyone else?


    That’s what I’ve been trying to find, but nothing seems to work. On his own page where I found this script, Mat Mullenweg just has it showing an image in a post. I think the issue is not so much where the image appears, but getting the side bar to refresh when the nav bar links are clicked. Is there something that could be added to the header.php to make this happen?

    For example could something be added to the a tags in the header.php nav bar so that when they’re clicked, the sidebar also refreshes? I’m sure this isn’t a complicated thing to do (but then I know you developers hear that all the time!)

    Of course this is difficult, because the links are created from the names of the pages on the database, not from any hardwired <a> tag. I think I’m going to give up. 🙁

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