WordPress.org

Ready to get started?Download WordPress

Forums

post order by discussion/activity (9 posts)

  1. alanft
    Member
    Posted 4 years ago #

    I've had a brief look through the plugin repository (and around the net) but not found what i was looking for.

    can anyone point me to a plugin that will show posts ordered by most recent comment. Something a bit like

    http://wordpress.org/extend/plugins/bt-actve-discussions/

    but that can be applied to the home page and (at least category) archive pages. perhaps using a GET parameter or an additional URL slug on the end (/activity, /comment, /bboard)

  2. MichaelH
    Member
    Posted 4 years ago #

  3. alanft
    Member
    Posted 4 years ago #

    thanks. i checked that c2c plugin and i realise on re-reading my initial post that i was being far from clear.

    what i am after is something that will change the standard Loop to show posts in a 'most recent comment' order rather than the usual blog standard order of 'most recently posted'.

  4. MichaelH
    Member
    Posted 4 years ago #

    Don't know about the standard loop as query_posts doesn't allow that kind of sort and filter would have to join to the wp_comments table.

    Look closer at that plugin...

  5. alanft
    Member
    Posted 4 years ago #

    thanks, i might end up using it as a make-do for now, but it's still not quite what i was after. [edit] i'm not sure i CAN get it to work. may be able to use some of the code in it though

    i'm going to have a bash to see if i can get the effect i'm after using the filters like posts_orderby.

  6. alanft
    Member
    Posted 4 years ago #

    just in case anyone ever googles back to this, here's what i'm trialling at the mo, and it's working ok, though not strongly tested...

    the code below in my functions.php gives an ordered by recent comment date with 25 results per page when you add ?bboard to the URL of the home page or an archive page.

    if (isset($_GET['bboard']))
    {	add_filter('posts_fields', 'bboard_posts_fields');
    	add_filter('posts_join_request', 'bboard_posts_join_paged');
    	add_filter('posts_groupby', 'bboard_posts_groupby');
    	add_filter('posts_orderby', 'bboard_posts_orderby');
    	add_filter('post_limits', 'bboard_post_limits');
    }
    
    function bboard_posts_fields($fields)
    {	return $fields.", MAX(comment_date) as max_comment_date, max(comment_ID) as latest_comment_id"; }
    
    function bboard_posts_join_paged($join)
    {	global $wpdb;
    	return $join." INNER JOIN wp_comments ON ( $wpdb->posts.ID = $wpdb->comments.comment_post_ID AND comment_approved=1) ";
    }
    
    function bboard_posts_groupby($groupby)
    {	if ($groupby=="") $groupby.=" wp_posts.ID";
    	return $groupby;
    }
    
    function bboard_posts_orderby($orderby)
    {	return "max_comment_date desc"; }
    
    function bboard_post_limits($limits)
    {	global $wp_query;
    	$q=$wp_query->query_vars;
    	if ($q['paged'] && $q['paged']>1) $offset = "offset ".(25*($q['paged']-1));
    	return "LIMIT 25 $offset";
    }

    within the loop, to get the content of that latest comment use

    $comment=get_comment($post->latest_comment_id);

    and then you can use standard comment tags like comment_excerpt() and get_comment_date() as normal

  7. alanft
    Member
    Posted 4 years ago #

    (talking to myself)

    i might work this up into a plugin now that i've got it listing posts by

    recent_posts (the standard 'blog view')
    recent_comments

    most_views
    least_views

    most_comments
    least_comments

  8. scottsemple
    Member
    Posted 4 years ago #

    @alanft: I'd be psyched if you put this into a plugin. I need the same thing.

  9. alanft
    Member
    Posted 4 years ago #

    it's been working well BTW, if anyone could advise me on what hooks etc to use to make it work with pretty URLs, rather than GET parameters, that would be awesome.

Topic Closed

This topic has been closed to new replies.

About this Topic