marcy_sss
Forum Replies Created
-
Forum: Plugins
In reply to: Hide/Show Comments ?uestionWell that was fast, I solved my own question. ?? Here is my solution for the above problem in case someone else runs into it! I was able to keep the javascript functionality of showing/hiding comments without a page reload by using a $_GET variable when coming from index.php.
The problem arose when clicking the “Comments” link below a post on index.php, it would take me to single.php with comments hidden, so I would have to click the Comments link twice to get them to show.
When my example goes live in a week or two (today is 3/25/09), the blog site will be located at https://www.thrivecommunities.com/blog .
Edit get_comments_link() function in wp-includes/comment-
template.php to generate a query string variable on index.php:function get_comments_link() { return get_permalink() . '?show=true'; // link was "#comments" anchor, you can keep it if your // page is really long }
In the Hide/Show Comments plugin, edit the file called hideshowcomments.php. Note: I have left off a few lines from the top of the plugin script that were unchanged in my efforts.
<?php function hideshowComments () { $linkText1 = __("Comments", "hideshowcomments"); $linkText2 = __("", "hideshowcomments"); $relinkText = __("Hide Comments", "hideshowcomments"); $show = $_GET['show']; echo " <script type=\"text/javascript\"> "; if($show == 'true'){ // show comments when coming from index.php echo "var currLayerId = \"hide\";\n"; $showLink = 'display:none'; $hideLink = 'display:block'; } else if($show == NULL) { // if there is no query string, hide comments like normal echo "var currLayerId = \"show\";\n"; $showLink = 'display:block'; $hideLink = 'display:none'; } echo " // create javascript functions 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=\"".$showLink.";\" class=\"feedback2\"> <a href=\"#\" style=\"text-decoration:none;\" onclick=\"togLayer('hide');return false;\" title=\"\">", $linkText1, " (", comments_number('0','1','%'), ") ", $linkText2, "</a> </div> <div id=\"hide\" style=\"".$hideLink.";padding:0;\"> <div class=\"hideCommentsLink\"><a href=\"#\" style=\"text-decoration:none;\" onclick=\"togLayer('show');return false;\" title=\"\">", $relinkText, "</a></div> ", comments_template(), "</div>"; } ?>
I am using custom CSS as well, which I have not included here. If you have problems feel free to contact me! me at marcyland dot com
Cheers!