Tribiq CMS

Choose your language

8.4 RSS (Really Simple Syndication)

Any Tribiq CMS Template can provide an RSS feed, based on the contents on the current page.

It is likely that you will want to enable RSS feeds on items that contain aggregated data, such as News Listings or Forums.

8.4.1 Enable RSS

You must first enable RSS for the chosen template. In the Admin Control Panel, go to Templates, and find the Template Details for the Template you wish to edit.

You will notice that there is an option called "Allow RSS Feed". Set this to Yes.

8.4.2 Generating RSS

Let's take the news listing page for example.

We know that the variable $news is already available to us - this contains an array which features the information about each News Article.

If you want to create a page which lists content which isnt already generated by the CMS, you may have to write a custom PHP function.

We can start formatting our RSS feed like so.

First, make sure you have a variable that contains aggregated information (PHP). Remember, this may alrady be defined on your template anyway:

$news = getShowableNews($news_listings_limit,$default_char_limit,$year_select,$lang);

You will need to include the following snippet in your template to intialize the RSS feed (PHP).

if ($_GET['rss']=="true") {
    $rss_output = "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
    $rss_output .= "<rss version=\"2.0\">\n";
    $rss_output .= "<channel>";
    $rss_output .= "    <title>NEWS FEED TITLE</title>\n";
    $rss_output .= "    <link>NEWS FEED LINK</link>\n";
    $rss_output .= "    <description>NEWS FEED DESC</description>\n";
   

It is likely that you will want to change the News Feed Title, Main Link (URL) and Description. Now you will need to include the loop section, that generates each article within the RSS feed (PHP).

foreach ($news as $news_article) {
        $rss_output .= "    <item>\n";
        $rss_output .= "        <title>" . $news_article['title'] . "</title>\n";
        $rss_output .= "        <link>http://tribiq.com" . SUBDIRECTORY . "?cID=".$news_article['id']."&amp;cType=news</link>\n";
        $rss_output .= "        <description>" . $news_article['content'] . "</description>\n";
        $rss_output .= "    </item>\n";
    }
   

As you can see, we are taking each piece of aggregated data from the set and writing an RSS pointer for it. You might want to use parts of the data in the link. Now we need to close the RSS feed:

    $rss_output .= "</channel>\n";
    $rss_output .= "</rss>\n";
   
    ob_end_clean();
   
    header('Content-type: application/xml; charset="utf-8"',true);

    echo $rss_output;
    exit;
}

Put these three snippets together and your template should now generate an RSS feed. This would be visible by your browser when your site visitors land on the webpage - In Firefox this may be identified by the RSS symbol or in Safari, "RSS", in the URL bar.

To provide a URL to your feed you should use the following syntax:

http://yourtribiqsite.com/?cID=x&cType=y&rss=true

where x is the content ID or alias, e.g. news, and y is the Content Type, e.g html.

Top of Page