WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Forcing the sidebar to refresh on each 'static' page link click (23 posts)

  1. dan.tee
    Member
    Posted 3 years ago #

    Hi,

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

  2. jeFFF
    Member
    Posted 3 years ago #

    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.

    Cheers,
    jeFFF

  3. dan.tee
    Member
    Posted 3 years ago #

    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.

  4. jeFFF
    Member
    Posted 3 years ago #

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

  5. dan.tee
    Member
    Posted 3 years ago #

    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.

  6. jeFFF
    Member
    Posted 3 years ago #

    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

  7. dan.tee
    Member
    Posted 3 years ago #

    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? :-)

  8. jeFFF
    Member
    Posted 3 years ago #

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

  9. dan.tee
    Member
    Posted 3 years ago #

    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?

  10. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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.

  11. dan.tee
    Member
    Posted 3 years ago #

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

  12. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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.

  13. dan.tee
    Member
    Posted 3 years ago #

    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?

  14. dan.tee
    Member
    Posted 3 years ago #

    @esmi

    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?

  15. dan.tee
    Member
    Posted 3 years ago #

    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!)

  16. dan.tee
    Member
    Posted 3 years ago #

    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. :-(

  17. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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 http://wordpress.pastebin.com/2dTDRk8H - although bear in mind that this is off the top of my head and is untested,

  18. dan.tee
    Member
    Posted 3 years ago #

    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!

  19. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    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.

  20. dan.tee
    Member
    Posted 3 years ago #

    OK, I'll give it a try!

  21. dan.tee
    Member
    Posted 3 years ago #

    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. :-(

  22. dan.tee
    Member
    Posted 3 years ago #

    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! ;-)

  23. dan.tee
    Member
    Posted 3 years ago #

    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!

Topic Closed

This topic has been closed to new replies.

About this Topic