Developers corner > Developer Lobby

Creating an RSS feed

(1/3) > >>

I am trying to create an RSS feed that displays the latest image from a certain gallery. Having never never written an xml template I'm finding it a challenge. Following the advice of the xml template guide I have looked at generic.php and todd_dominey.php, I was thinking that since an rss feed needs a different layout than a flash gallery template it would be better to not try to extend the generic.php ?

One problem I am having is how to restrict the template to one gallery, I only want the feed to call images from a specific gallery.

An rss2 feed needs a layout similar to this (I have shown what a "latest image" feed's structure would look like:

<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="" ?>
<rss version="2.0">
<title>Latest from   X-GALLERY</title>
<link>Link to main site</link>
<description>This is the latest from    GALLERY</description>
<lastBuildDate>DATE OF LATEST IMAGE in this format Mon, 12 Sep 2005 18:37:00 GMT</lastBuildDate>
<title>Title of LATEST IMAGE</title>
<link>Link to latest image page</link>
<guid>Link to latest image page</guid>
<pubDate>DATE OF LATEST IMAGE in this formatMon, 12 Sep 2005 18:37:00 GMT</pubDate>
<description>[CDATA[ <img src"link to image" /><br />Description of LATEST IMAGE. ]]</description>

I have attached the file which I am working on at the moment. As it is I have the basic layout and I am now trying to find the variables to exchange for the labels. To start with I am attempting to use the code for the function showLatest from display.class.php but I have no idea if this would work and there are a lot more variables that I need to work out.

link to home page (can I use $GLOBALS[mosConfig_live_site] ?)
name of x-gallery
title of latest image
link to latest image
direct link to latest image to display in feed (i.e <img src="">)
date the image was entered into the db (used for both lastBuildDate and pubDate
image description

For now I am going to try and take the variables from display.class.php and see how that works, any help to speed this along would be much appreciated :)

Also, does anyone know if I can put php snippets in a CDATA section?
Many thanks,

[attachment no longer available]

Hi Mike,

You pretty much have to extend generic.php and it will be easiest to do so. Here's what you need to do:

In the URL to xml file add &gid=43.  This will autoload the gallery with ID 43.

Here's some pseudo code for how your file should look like:

--- Code: ---class rsgXmlGalleryTemplate_rss_latest extends rsgXmlGalleryTemplate_generic{

    function getName(){
        return 'RSS Latest';
    function prepare(){
    $images = $this->gallery->items();
    $images now contains an array of database row arrays representing the images in the chosen gallery.  sort $images by date
    assign xml to $this->output.  $this->output is later echoed 
--- End code ---

you might want to do a print_r() on $images to see for yourself what it contains.  you can then use standard php sorting functions to sort $images and obtain the latest image.  by default $images is ordered by ordering.

Sometime early in the 1.14 series the filter_order will be implemented and save you from having to manually sort the images.  So that functionality would be handy here but it's not finished yet.

Is there a way of adding an RSS feed created for RSGallery to the main rss feed of a joomla site, it seems strange to have two rss feed, one for content and one for images.

That's an interesting idea.  The only way to do that is create a custom RSS feed that did both at the same time.  The default RSS feed only publishes news items on the frontpage.


[0] Message Index

[#] Next page

Go to full version