This site uses cookies from Google to deliver its services, to personalize ads and to analyze traffic. Information about your use of this site is shared with Google. By using this site, you agree to its use of cookies. Learn More

[Web-development (jquery)] Display Most Popular Posts in WordPress

Display Most Popular Posts in WordPressDisplay Most Popular Posts in WordPress








<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); ?>">
<?php echo $title ?></a> {<?php echo $commentcount ?>}</li>
<?php } } ?>
</ul>

Just change the 5 in line 3 to change the number of displayed popular posts

0 Response to "[Web-development (jquery)] Display Most Popular Posts in WordPress"

Posting Komentar

Contact

Nama

Email *

Pesan *