756547
That makes two of us. I love the idea of the Popularity plugin, but it definitely doesn’t work with the latest WordPress (2.6).
SELECT comment_post_ID , COUNT(comment_post_ID)
FROM wp_comments
GROUP BY comment_post_ID
ORDER BY COUNT( comment_post_ID ) DESC
LIMIT 10 ;
This SQL statement does the trick. It returns the 10 most commented upon post IDs.
Now if someone can make a plugin out of this …
Er. There is something much easier –
SELECT ID
FROM wp_posts
ORDER BY comment_count DESC
LIMIT 10;
D’oh. If you want to show the 5 most popular posts in your template, you can use something like this –
<?php
$sql='SELECT post_title, comment_count, guid
FROM wp_posts
ORDER BY comment_count DESC
LIMIT 5;';
$results = $wpdb->get_results($sql);
foreach ($results as $r) {
echo '<li><a href="' . $r->guid . '" title="' . $r->post_title . '">· ' . $r->post_title .
' <em>(' . $r->comment_count . ')</em></a></li>';
}
?>
Before WP 2.5 it was possible to use:
$lastposts = get_posts('numberposts=10&orderby=comment_count&offset=0');
Is there no function that works simpler ones as the solution of pravin?
pravin, where should i edit this script? in which file?
haimski … in your template file, where you need it.
Most probably in a sidebar.php, otherwise in the index.php.