Most Commented Posts Widget
Lists the posts with the most approved comments on the dashboard, a quick read on what sparks conversation.
Opens WPIDE on
Code
add_action( 'wp_dashboard_setup', function () {
if ( ! current_user_can( 'edit_posts' ) ) {
return;
}
wp_add_dashboard_widget( 'wpide_most_commented', 'Most Commented', function () {
$posts = get_posts( array(
'post_type' => 'post',
'numberposts' => 8,
'orderby' => 'comment_count',
'order' => 'DESC',
) );
echo '<ol>';
foreach ( $posts as $item ) {
if ( ! $item->comment_count ) {
continue;
}
printf(
'<li><a href="%1$s">%2$s</a> <span style="color:#646970">(%3$s)</span></li>',
esc_url( get_permalink( $item ) ),
esc_html( get_the_title( $item ) ),
esc_html( number_format_i18n( $item->comment_count ) )
);
}
echo '</ol>';
} );
} );
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.