WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] sort posts by number of comments (4 posts)

  1. James
    Member
    Posted 4 years ago #

    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

  2. MichaelH
    Member
    Posted 4 years ago #

    <?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()

  3. James
    Member
    Posted 4 years ago #

    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

  4. MichaelH
    Member
    Posted 4 years ago #

    CSS

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.