The shortcode to display quantity of post comments
With the help of this shortcode you can display the number of comments that users left to the post with the identifier ‘postid’ out of a Single page for example in Archives.
function get_comments_quantity( $atts, $content = null ) { $atts = shortcode_atts( array( 'postid' => '', ), $atts); $num_comments = get_comments_number( $atts['postid'] ); if ( comments_open() ) { if ( $num_comments == 0 ) { $comments = __('No Comments', 'rehub_framework'); } elseif ( $num_comments > 1 ) { $comments = $num_comments . __(' Comments', 'rehub_framework'); } else { $comments = __('1 Comment', 'rehub_framework'); } $write_comments = '<a href="' . get_comments_link( $atts['postid'] ) .'">'. $comments.'</a>'; } else { $write_comments = __('Comments are off for this post.', 'rehub_framework'); } return $write_comments ; } add_shortcode( 'comments_quantity', 'get_comments_quantity' );