Last active
August 29, 2015 14:04
-
-
Save NearlyNormal/e4776787c4d6a60b9ebb to your computer and use it in GitHub Desktop.
Wordpress recent posts with comment count in sidebar template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$args = array( | |
'orderby' => 'date' | |
,'order' => 'DESC' | |
,'showposts'=>6 | |
); | |
$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 '; } | |
else { $recent_count = "$recent_count <span class='iv'>Comments </span>"; } | |
echo "<dt>$recent_date / <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>" | |
echo "</dl>"; | |
endwhile; | |
} | |
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