Quantcast
Channel: WordPress Cheat Sheets » admin
Viewing all articles
Browse latest Browse all 39

Genesis Theme – Show Total Number of Comments in a Post

$
0
0

The Genesis theme by default shows the text “comments” for the comment section of a WordPress post. Use the following snippet of code in your “functions.php” file to show the total number of comments of the post too:

add_filter( 'genesis_title_comments', 'custom_genesis_title_comments' );
function custom_genesis_title_comments($title)
{
global $post;
if(isset($post->ID)){
//Get the total number of comments of this post
$total_comments = get_comments_number( $post->ID );
if ($total_comments > 1){//Show total number of comments if there are more than 1 comment
$title = '<h3>Comments ('.$total_comments.' responses)</h3>';
}
}
return $title;
}

You can also use the comments_number function to format the total number of comments in a post nicely. Here is an example of how to use the “comments_number” function:

echo 'This post currently has'. comments_number( 'no responses', 'one response', '% responses' );

Viewing all articles
Browse latest Browse all 39

Trending Articles