WordPress.org

Ready to get started?Download WordPress

Forums

RSS: How to include number of post comments in post title? (3 posts)

  1. edmicman
    Member
    Posted 7 years ago #

    In my RSS feed, I want to append to the end of each post title the number of comments on that post if there are any, ie:

    Post Title 1 (1)
    Post Title 2
    Post Title 3 (4)

    I've done this in the past by modifying the theme, and then using MagpieRSS on another site to aggregate everything. However, the main RSS feed isn't updated unless a new post is made; creating a new comment doesn't update the timestamp of the posts' feed, and so Magpie doesn't update it.

    Is there a way to, when the comments rss is updated, to update the timestamp of the main rss feed? Or even better, a plugin or something that would do what I want to do with the feeds?

  2. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    If you look in the wp-rss2.php file, you'll find this bit of code:
    <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></pubDate>

    If you change that to this:
    <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastcommentmodified('GMT'), false); ?></pubDate>

    Then your RSS will show as updated whenever you get a new comment or modify an existing one.

    As for adding the comment number to the title in the feed only:

    function append_comment_count_to_title($title) {
    return $title . ' (' . get_comments_number() . ')';
    }
    add_filter('the_title_rss','append_comment_count_to_title');

    Add that to your theme's functions.php file, and it'll do it automagically.

  3. edmicman
    Member
    Posted 7 years ago #

    Awesome - thanks!

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags