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

Viewing 8 replies - 1 through 8 (of 8 total)
  • Thread Starter alanft

    (@alanft)

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

    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…

    Thread Starter alanft

    (@alanft)

    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.

    Thread Starter alanft

    (@alanft)

    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

    Thread Starter alanft

    (@alanft)

    (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

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

    Thread Starter alanft

    (@alanft)

    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.

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘post order by discussion/activity’ is closed to new replies.