WordPress.org

Support

Support » Plugins and Hacks » [Resolved] sort posts by number of comments

[Resolved] sort posts by number of comments

  • James

    @james-callaway

    Hey there folks…

    I’m looking for a plugin or query string that will display full posts in order of most to least comments.

    Thanks in advance!

    JC

Viewing 3 replies - 1 through 3 (of 3 total)
  • <?php
    $args=array(
      'orderby'=>'comment_count',
      'order'=>'DESC',
      'post_type' => 'post',
      'post_status' => 'publish',
      'posts_per_page' => -1,
      'caller_get_posts'=> 1
    );
    $my_query = null;
    $my_query = new WP_Query($args);
    if( $my_query->have_posts() ) {
      echo 'List of Posts';
      while ($my_query->have_posts()) : $my_query->the_post(); ?>
        <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
        <?php
        the_content();
      endwhile;
    }
    wp_reset_query();  // Restore global post data stomped by the_post().
    ?>

    Related:
    Stepping Into Template Tags
    Stepping Into Templates
    Template Hierarchy
    query_posts()

    James

    @james-callaway

    Hey Michael,

    Thanks, that works great!

    Now to make a complete pain in the @$$ of myself… how do I refine this so that the display looks the same as the blog page with all the comments and ratings and formatting, etc?

    JC

    CSS

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘[Resolved] sort posts by number of comments’ is closed to new replies.
Skip to toolbar