Forums

Browsing posts by number of comments (3 posts)

  1. marcboivin
    Member
    Posted 1 year ago #

    I'm looking for a way to allow my users to browse my blog by most commented posts. Googling for it led to nothing really.

    I'm guessing I would need to hook the redirecting functions, add support for a canonical tag like /by-comment/, but really I don't know where to start from.

    Any ideas?

    TIA

  2. Rev. Voodoo
    Volunteer Moderator
    Posted 1 year ago #

    interested in a plugin at all?

    I use:
    http://wordpress.org/extend/plugins/most-commented/
    but rather than widget I use it in my archive template

    which works with this bit of code:

    <?php if( function_exists('mdv_most_commented') ) : ?>
    
    					<h6><?php _e( 'Most Commented Posts', 'voodoo_lion' ); ?></h6>
    					<ul>
    					<?php mdv_most_commented(10); ?>
    					</ul>
    
    					<?php endif; ?>

    to show my ten most commented post titles....

  3. Mark / t31os
    Moderator
    Posted 1 year ago #

    You could do this using WP_Query to create a query ordered by comment count.

    Example

    <?php
    $most_comments_posts = new WP_Query;
    $most_comments_posts->query( array(
    	'posts_per_page' => 10,
    	'orderby' => 'comment_count',
    	'order' => 'desc'
    ) );
    
    if( $most_comments_posts->have_posts() ) :
    	while( $most_comments_posts->have_posts() ) :
    	?>
    
    	<!-- example html area -->
    	<div class="example">
    
    	<?php
    	// Like a regular loop, you can place the various template tags here: http://codex.wordpress.org/Template_Tags
    	the_title(); // Example
    	?>
    
    	</div>
    	<!-- example html area -->
    
    	<?php
    	endwhile; // End loop
    endif; // End if loop has posts
    ?>

Topic Closed

This topic has been closed to new replies.

About this Topic