WordPress.org

Ready to get started?Download WordPress

Forums

comments_popup_link Needs Work (12 posts)

  1. war59312
    Member
    Posted 7 years ago #

    Hi,

    Looks like comments_popup_link needs some work. As in it should only count the number of comments and display the link. At the moment it counts comments, pingbacks, and trackbacks all as comments. :(

    Would also be nice if too additional functions could be added, thinking something like "pingback_popup_link" and "trackback_popup_link".

    Sadly it looks like that is how was about three years ago:

    http://trac.wordpress.org/changeset/104

    Please change this back or rename the function since it implies it only prints out the number of comments when in fact it does all three.

    So is there now no way to simply print out the real number of comments? pingbacks? trackbacks?

    Thanks a lot,

    Will

  2. war59312
    Member
    Posted 7 years ago #

    Um, another function that assumes all three are comments:

    <?php $numOfComments = get_comments_number(); echo $numOfComments; ?>

    For example it will print "5" when there is 3 trackbacks and 2 comments. :(

  3. war59312
    Member
    Posted 7 years ago #

    Anyone got any ideas on how I can do this at least?

  4. war59312
    Member
    Posted 6 years ago #

    1 and only bump

    thanks!

  5. Chris_K
    Member
    Posted 6 years ago #

    That's pretty much the way things are: Comments, trackbacks and pingbacks are all treated the same.

    If you want to Present them differently, you certainly can. That's something you do at the theme (presentation) level.

    For instance, I show all my trackbacks/pingbacks in a list first, then the comments.

  6. war59312
    Member
    Posted 6 years ago #

    Yes that is what I do now, but I just want to count them as what they really are. For example a topic has 15 comments, 5 trackbacks, and 3 pingbacks. Not 23 comments.

  7. Chris_K
    Member
    Posted 6 years ago #

    Well... if you lump track/ping backs together, you could do something like this:

    <?php /* Count the totals */
    	$numPingBacks = 0;
    	$numComments  = 0;
    
    	foreach ($comments as $comment) {
    		if (get_comment_type() != "comment") {
    			$numPingBacks++;
    		} else {
    			$numComments++;
    		}
    	}
    	?>
  8. war59312
    Member
    Posted 6 years ago #

    Hi,

    Thanks, that works on comments.php within the loop, but not outside the loop, like on post.php.

    Sorry, should have mentioned it, I am looking to display the number of comments, number of trackbacks, and number of pingbacks, for each post via post.php outside the loop.

    Also, I noticed the above code works fine for comments but it treats trackbacks and pingbacks as one. Anyway to separate the two?

    Thanks again,

    Will

  9. Chris_K
    Member
    Posted 6 years ago #

    I don't have the entire answer, but maybe this'll get you closer...

    On my blog, this query:

    SELECT comment_type, count( comment_type )
    FROM <code>wp_comments</code>
    WHERE comment_post_id =937
    GROUP BY comment_type

    (where 937 = post_id) results in:

    Count comment_type count( comment_type )
    30
    pingback 63
    trackback 3

    (pardon the formatting).

    Comments are blank. But pingback/trackbacks are differentiated at the db level, so there's hope...

  10. war59312
    Member
    Posted 6 years ago #

    Hey,

    I got to really learn PHP and mysql one of these days... lol

    I am sure this sucks big time and it is much easier than this:

    <?php
    
    $numberOfComments = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = '' GROUP BY 'comment_type' ");
    
    $numberOfTrackbacks = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = 'trackback' GROUP BY 'comment_type' ");
    
    $numberOfPingbacks = $wpdb->get_var("SELECT COUNT( comment_post_ID ) FROM $wpdb->comments WHERE comment_post_ID = '$post->ID' AND comment_type = 'pingback' GROUP BY 'comment_type' ");
    
    	if ($numberOfComments != "" && $numberOfComments == 1) {
    
    		echo $numberOfComments; echo " comment ";
    
    		} else if ($numberOfComments > 1) {
    
    			echo $numberOfComments; echo " comments ";
    
    		}
    
    	if ($numberOfTrackbacks != "" && $numberOfTrackbacks == 1) {
    
    		echo $numberOfTrackbacks; echo " trackback ";
    
    		} else if ($numberOfTrackbacks > 1) {
    
    			echo $numberOfTrackbacks; echo " trackbacks ";
    
    		}
    
    	if ($numberOfPingbacks != "" && $numberOfPingbacks == 1) {
    
    		echo $numberOfPingbacks; echo " comment ";
    
    		} else if ($numberOfPingbacks > 1) {
    
    			echo $numberOfPingbacks; echo " comments ";
    
    		}
    
    ?>

    Take Care,

    Will

  11. shareh
    Member
    Posted 6 years ago #

    Hi,

    Thanks, that works on comments.php within the loop, but not outside the loop, like on post.php.

    Sorry, should have mentioned it, I am looking to display the number of trackbacks, and number of pingbacks, for each post .

    please help me

  12. war59312
    Member
    Posted 6 years ago #

    I dont m8. I need some help still too...

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.