Add Number of Comments

From IThemes Codex
Jump to: navigation, search

This function will insert the number of comments as a linked entry. Add the following code at the end of your functions.php file (but before the closing ?>, if any).

Code

function my_insert_comments_count() {
    
    $num_comments = get_comments_number();

    if ( comments_open() ) {
    	if ( $num_comments == 0 ) {
    		$comments = __('No Comments');
    	} elseif ( $num_comments > 1 ) {
    		$comments = $num_comments . __(' Comments');
    	} else {
    		$comments = __('1 Comment');
    	}

        $return_comments = '<a href="' . get_comments_link() .'">'. $comments.'</a>';
    } else {
       	$return_comments =  __('Comments disabled for this post.');
    }
 
    return $return_comments;
    
}
add_shortcode('insert-comments-count', 'my_insert_comments_count');

Usage

Insert the shortcode [insert-comments-count] in your LoopBuddy layout where you want the number of post views to show up.


← Back to LoopBuddy Codex Home

Personal tools
Namespaces
Variants
Actions
iThemes Codex
Codex Navigation
Toolbox