Show comment counts beside popular posts

Append the number of comments to each result in a Top 10 popular-posts list.

What it changes

The function appends the result object’s comment_count value and the text comments to the Top 10 list item.

Presentation

The example uses the same wording for every count, including one comment. Review the label and placement for your site. This displays comments, not the post’s view count.

Requirements

  • Top 10
  • Top 10 must be active and provide a comment_count value on each result.

Source

top-10/outputs/tptn-comments-count.php
<?php
/**
 * Plugin Name: Top 10 - Add Comments Count
 * Plugin URI:  https://webberzone.com/plugins/top-10/
 * Description: Adds the number of comments to the items in the popular posts list.
 * Author: Ajay D'Souza
 * Author URI: https://webberzone.com
 * Version: 1.0
 *
 * @package Top_Ten
 * @license GPL-2.0+
 */

/**
 * Add comments count to the list items.
 *
 * @param string $output Formatted list item with link and and thumbnail.
 * @param object $result Object of the current post result.
 *
 * @return string  Output variable with comments number added
 */
function tptn_comments_count( $output, $result ) {

	$output .= ' ' . $result->comment_count . __( ' comments', 'top-10' );

	return $output;
}
add_filter( 'tptn_list', 'tptn_comments_count', 10, 2 );

Details

Type
Plugin
Last updated
GitHub
Source · Edit companion · History

Developer references