PHP Script Forums » bbpress plugins and modifications

Important RSS feed mod

(2 posts)

Tags:

Please support us by buying these products:

  1. Olaf

    Olaf
    PHP Coder

    In the current version the RSS feeds show all the last posts even if the last five are all from the same topic. Most of all in not so active forums, this original RSS feed is not very useful.

    Next in each feed you will find all posted information in this feed, actually it's a 1:1 copy from the forum. Here are very big disadvantages while using this feed:

    • Content duplication for search engines
    • The risk that other webmaster will copy your content and post them on their own forums or websites
    • People don't need to get back to your forum because they can read every post in their feed reader

    I think that this bad function will get an update very soon in some future update of bbpress, thats why I created this mod (don't think that a 100% working plugin is needed).

    First you need to add this two function to your personal plugin file:

    function substr_words($str, $txt_len) {
    	$words = explode(' ', $str);
    	$count = 0;
    	$new_str = '';
    	$abbr = '';
    	foreach ($words as $val) {
    		if ($count < $txt_len) {
    			$new_str .= $val.' ';
    			$count = $count + strlen($val);
    		}
    	}
    	$new_str = rtrim($new_str, ' ,.;:');
    	$new_str .= (strlen($str) > $txt_len) ? ' [...]' : '';
    	return $new_str;
    }
    
    function short_post_text($post_id = 0) {
    	$post = get_post_text($post_id);
    	$short_text = substr_words($post, 150);
    	echo apply_filters('post_text', $short_text, get_post_id($post_id));
    }

    If you don't know how-to create a plugin file, just past the two function to the top of the rss2.php template file.

    Next we need to change the foreach loop within the RSS template file (this is a replace memt for the RSS items part):

    <?php
    $topics = array();
    foreach ($posts as $bb_post) {
    	if (!in_array($bb_post->topic_id, $topics)) {
    		$topics[] = $bb_post->topic_id;
    ?>
    <item>
    <title><?php topic_title( $bb_post->topic_id ); ?></title>
    <link><?php post_link(); ?></link>
    <pubDate><?php bb_post_time('D, d M Y H:i:s +0000'); ?></pubDate>
    <dc:creator><?php post_author(); ?></dc:creator>
    <guid isPermaLink="false"><?php bb_option('uri'); ?></guid>
    <description><?php short_post_text(); ?></description>
    </item>
    <?php
    	}
    }
    ?>

    Thats all, this mod works for all RSS feeds. If you have any comments or questions than let me know.

    Posted 1 year ago #
  2. Olaf

    Olaf
    PHP Coder

    Before I forget this:

    change also the link elements to those RSS feeds and add "nofollow"

    Posted 9 months ago #

RSS feed for this topic

Reply

You must log in to post.