Skip to content

Instantly share code, notes, and snippets.

@NearlyNormal
Created August 3, 2014 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NearlyNormal/29b9b7067e9ae561c8a6 to your computer and use it in GitHub Desktop.
Save NearlyNormal/29b9b7067e9ae561c8a6 to your computer and use it in GitHub Desktop.
Wordpress recent posts with comment count in sidebar template
<?php
$currentID = get_the_ID();
$args = array(
'orderby' => 'date'
,'order' => 'DESC'
,'showposts'=>6
,'post__not_in' => array($post->ID)
);
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
echo "<dl>";
while ($my_query->have_posts()) : $my_query->the_post();
$recent_title = get_the_title();
$recent_link = get_the_permalink();
$recent_date = get_the_date();
$recent_count = $post->comment_count;
if ($recent_count < 1) { $recent_count = 'Leave a Comment&nbsp;'; }
else { $recent_count = "$recent_count <span class='iv'>Comments&nbsp;</span>"; }
echo "<dt>$recent_date &nbsp; / &nbsp; <span class='comment'><a href='$recent_link#disqus_thread'>$recent_count</a></span></dt><dd><a href='$recent_link' title='$recent_title'>$recent_title</a></dd>";
endwhile;
echo "</dl>";
}
wp_reset_query(); // Restore global post data stomped by the_post().
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment