Hide/Show Comments ?uestion
-
Hello Everyone!
I am really close to being done with my first WordPress install, but I have one little bug to squash. ??
https://thrivecommunities.com/test/blog
I am using the Hide/Show comments plugin. My problem is on index.php — when you click on Comments(2) below the post (I only show one post at a time), it goes to single.php with the comments hidden, how it should be when you click a permalink, however users will expect comments to show when they click Comments(2).
SO, I either need to redirect from index.php straight to the first post’s permalinked page (easiest), or figure out a way to toggle comment visibility via the URL.
Has anyone else run into this problem?
I tried changing the get_comments_link() function in wp-includes/comment-template.php to generate a query string:
function get_comments_link() { return get_permalink() . '?show=true'; }
Then in the plugin’s php page, use PHP with Javascript to toggle the comments on and off:
// escape slashes removed below for readability echo "<script type="text/javascript"> "; if($_GET['show'] == 'true'){ echo "var currLayerId = 'hide'"; } else { echo "var currLayerId = 'show'"; } echo " function togLayer(id) { if(currLayerId) setDisplay(currLayerId, "none"); if(id)setDisplay(id, "block"); currLayerId = id; } function setDisplay(id,value) { var elm = document.getElementById(id); elm.style.display = value; } </script> <div id="show" style="display: block;"> <a href="?show=false" onclick="togLayer('hide');return false;" title="">", $linkText1, " (", comments_number('0','1','%'), ") ", $linkText2, "</a> </div> <div id="hide" style="display:none;"> <a href="?show=true" onclick="togLayer('show');return false;" title="">", $relinkText, "</a></div>
This isn’t working, obviously. I’m guessing the problem is with the inline style=”display:none;” — Any suggestions on how to make this work dynamically?
Thanks a million!
-Marcy
- The topic ‘Hide/Show Comments ?uestion’ is closed to new replies.