Created
August 3, 2014 13:57
-
-
Save NearlyNormal/29b9b7067e9ae561c8a6 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 | |
$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 '; } | |
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>"; | |
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