Gemafernandez78 Posted November 6, 2014 Share Posted November 6, 2014 I have a problem with the "comments count" in the toggle link in my blog: www.albertosotophotography.com I have this script for show/hide comments in main page: <script type= "text/javascript"> // Show/Hide Comments jQuery(document).ready(function() { // Get #comments div var uniqueAppend = 1; var tempName = 'comments'; while(jQuery("#comments").length > 0 ){ jQuery("#comments").attr('id',tempName + uniqueAppend++).addClass('commentContainer') } var commentsDiv = jQuery('.commentContainer'); // Only do this work if that div isn't empty if (commentsDiv.length) { // Hide #comments div by default jQuery(commentsDiv).hide(); // Append a link to show/hide jQuery('<a/>') .attr('class', 'toggle-comments') .attr('href', '#') .html('Notes') .insertAfter(commentsDiv); // Encase button in .toggle-comments-container div jQuery('.toggle-comments').wrap(jQuery('<div/>', { class: 'toggle-comments-container' })) // When show/hide is clicked jQuery('.toggle-comments').on('click', function(e) { e.preventDefault(); // Show/hide the div using jQuery's toggle() var commentContainer = jQuery(this).parent('.toggle-comments-container').prev('.commentContainer'); jQuery(commentContainer).slideToggle('slow', function() { // change the text of the anchor var anchor = jQuery(commentContainer).siblings('.toggle-comments-container').children('.toggle-comments'); var anchorText = anchor.text() == 'Notes' ? 'Hide' : 'Notes'; jQuery(anchor).html(anchorText); }); }); } // End of commentsDiv.length }); // End of Show/Hide Comments </script> I use: .html('<?php comments_number( '0 notes', '1 note', '% notes' ); ?>') for name the "comments toggle link" with the count of comments for each single post. The problem is that all posts shows the same count: the comments presents in the first post. Someone can help me? Alberto Quote Link to comment https://forums.phpfreaks.com/topic/292309-how-to-get-count-comments-for-multiple-comments-page/ Share on other sites More sharing options...
ginerjm Posted November 6, 2014 Share Posted November 6, 2014 Perhaps I'm reading this wrong, but I don't see any PHP code in this problem. Maybe you want to post this to the correct forum? Quote Link to comment https://forums.phpfreaks.com/topic/292309-how-to-get-count-comments-for-multiple-comments-page/#findComment-1495922 Share on other sites More sharing options...
hansford Posted November 7, 2014 Share Posted November 7, 2014 You are calling a function "comments_number" - that function is getting the data from somewhere - usually a database. Check what that function returns without jQuery or anything else involved. You whittle the problem down piece by piece. Quote Link to comment https://forums.phpfreaks.com/topic/292309-how-to-get-count-comments-for-multiple-comments-page/#findComment-1495988 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.