Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to be able to display a list of posts on a page depending on when and how many comments they've got. Something similar to how it is here on stackexchange.

To be more specific, I want:

  • A page with the most commented posts.
  • A page with the most recently commented posts.
  • A page with all the uncommented posts.

Help with this would be very appreciated, thanks in advance.

share|improve this question
1  
@Patrik: Where and how do you want to display them? As sticky posts, in a sidebar widget, or other? More details will help us answer. –  MikeSchinkel Sep 8 '10 at 17:12
    
As a page with a list of blog posts. Just like a blog but instead of having the latest post show up first, the 2nd latest post after that etc, they are displayed depending on the conditions mentioned above. I hope you understand what I mean, english is not my primary language :) –  Patrik Sep 8 '10 at 17:17
add comment

4 Answers 4

query_posts( array('orderby' => 'comment_count', 'order'=>'DESC') )

This should do it.

share|improve this answer
add comment
$query = WP_Query;

foreach ($query['posts'] as $post){
  $count = $post['comment_count'];
  while (is_set($comment_sort[$count]){
   $count--;
  }    
  $comment_sort[$count]=$post['ID'];
}

$sorted = ksort($comment_sort);
$sorted = array_reverse($sorted);

this should give you an array of post ID's in decending order of comment counts.

share|improve this answer
add comment

@Patrik - I had a similar problem: In a WPMu installation, show the latest posts in post-order on the main blog. The easiest solution for me was to create a new table that holds the data for new blog posts (new posts are inserted via a plugin), and query that table for the main page. You can do the same, and just edit the SQL query to return based on most comments, etc.

share|improve this answer
add comment

Posts with recent comments:

$comments = get_comments( array(
    'status' => 'approve',
    'number' => 10
) );

$include = array();

foreach ( $comments as $comment )
    $include[] = $comment->comment_post_ID;

query_posts( array(
    'post__in' => array_unique( $include )
) );
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.