Posts Tagged ‘ WordPress Posts ’
Popular Posts in WordPress
Thursday, March 4th, 2010When you start working with WordPress on a new CMS site, it is clever to make your content visible to the audience with different ways. Here is a code hack, that can help you build a “Popular Posts” area.
<h2>Popular Posts</h2>…
<ul>
<?php $result = $wpdb->get_results("SELECT comment_count,ID,post_title
FROM $wpdb->posts ORDER BY comment_count DESC LIMIT 0 , 5");
foreach ($result as $post) {
setup_postdata($post);
$postid = $post->ID;
$title = $post->post_title;
$commentcount = $post->comment_count;
if ($commentcount != 0) { ?>
<li><a href="<?php echo get_permalink($postid); ?>" title="<?php echo
$title ?>">
<?php echo $title