Render Comments RSS
The method renderCommentsRSS() renders an RSS feed of a limited number of your Blog Comments. The method can be called from any of your ProcessWire pages.
<?php /** * Render a limited number of comments RSS. * * As seen on the frontend page: /blog/comments/rss/ * * @access public * @param int $limit * */ public function renderCommentsRSS($limit)
The method takes only one argument $limit which has to be an integer. If specified, it will limit the number of comments RSS rendered to the specified value. The method's usage is quite simple as shown below. Similar to the method renderRSS(), no futher markup should be output after calling this method as the RSS is output directly. Otherwise, you will get an error. Similarly too, the module RSS Feed Generator has to be installed for renderCommentsRSS() to work. It is a ProcessWire core module but may not be installed by default.
<?php //first we call MarkupBlog $blog = $modules->get('MarkupBlog'); $limit = 5; if($input->urlSegment1) { // rss feed if($input->urlSegment1 != 'rss') throw new Wire404Exception(); $blog->renderCommentsRSS($limit); //this is important: stops output of any other markup except the RSS xml return; }
In the code above, we limit the number of comments in our RSS feed to 5. We use the URL segment '/rss/' to specify when we want the feed to be output. The output from the above code would be similar to the following.
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0"> <channel> <title>- Code Tests</title> <link>http://localhost/pwtests/code-tests/</link> <description/> <pubDate>Wed, 27 Aug 2014 20:36:41 +0100</pubDate> <ttl>60</ttl> <item> <title>kongondo reply to: ProcessWire</title> <description> <![CDATA[ testing summbisls.s. ]]> </description> <pubDate>Fri, 22 Aug 2014 13:18:11 +0100</pubDate> <link>http://localhost/pwtests/blog/posts/example-post/</link> <guid>http://localhost/pwtests/blog/posts/example-post/</guid> </item> </channel> </rss>
Summary
The method renderCommentsRSS($limit) renders an RSS feed of a limited number of our Blog Comments. Since it outputs the RSS directly, no further markup should be output once the method has been called.