WordPress.org

Forums

Popular Posts Plugin (8 posts)

  1. steadyvibe
    Member
    Posted 7 years ago #

    I have spent the last 2 hours googling and searching for a popular posts plugin that works with 2.5. I can not find one thing that works.

    Has anyone done this in 2.5? I would also like it to grab an image as well from the post if possible.

    Thanks!

  2. Anonymous
    Unregistered
    Posted 7 years ago #

    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).

  3. Pravin Paratey
    Member
    Posted 7 years ago #

    Bumping this up :D

  4. Pravin Paratey
    Member
    Posted 7 years ago #

    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 ...

  5. Pravin Paratey
    Member
    Posted 7 years ago #

    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>';
    	}
    ?>
  6. webserviceXXL
    Member
    Posted 7 years ago #

    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?

  7. haimski
    Member
    Posted 6 years ago #

    pravin, where should i edit this script? in which file?

  8. mores
    Member
    Posted 6 years ago #

    haimski ... in your template file, where you need it.
    Most probably in a sidebar.php, otherwise in the index.php.

Topic Closed

This topic has been closed to new replies.

About this Topic