Alternative RSS Method (Zenfolio, Flickr, etc.,)
Jun 12th, 2008 | By dikiem | Category:WordPress Tips and Hack | 2 comments | 497 views |I had mentioned in the Wordpress Plugin section, there is an Zenfolio RSS plug that is used to display nice little thumb nails on the side bar of your Zenfolio Galleries. In search of finding something more specific, I came across an alternative method. While it is no plug in yet, but a simple PHP / HTML knowledge could get you going with this. You can see a sample of it operating in my Flower Photographs section here (http://knguyentu.com/wordpress/photography-by-kevin/flowers-photographs/)
The RSS engine I used there is RSS Parser for PHP5+ (http://rssphp.net/).
Download this RSS file and place it in the same folder as the theme files you are using. In my case, I’ve placed inside ./wordpress/wp-content/themes/(theme name)/… In another words, in the same location the theme index.php file is located.
Once you’ve place the RSS file there, you will need to setup a page to use as a template for your rss. You can easily make a copy of the page.php provided by your theme. Let’s copy it and call it photographs.php.
Now for the fun part. Edit the photographs.php and place the code in here, somewhere towards the bottom before the sidebar and/or footer calls.
<?php
$values = get_post_custom_values("photoRSS");
// echo $values[0];
require_once 'rss_php.php';
$rss = new rss_php;
$rss->load($values[0]);
$items = $rss->getItems();
$html = '';
foreach($items as $index => $item) {
$html .= '<h3><a href="'.$item['link'].'" title="'.$item['title'].'">'.$item['title'].'</h3>';
$html .= '</a><br />'.$item['description'].'<br />';
$html .= "<br />;
}
echo $html;
?>
This will loop through the RSS code and strip out the the RSS feed file and present it as your see int he example. You could wrap some HTML in the “$html” section in the code above to make the box look fancy and colorful if you like.
To be a bit more creative, with how the code is now, it will RSS pull all items in the RSS feed. You could add a simple loop around the code and limit how many items to pull per feed. See the code snip below. In BOLD is what was added to accommodate that.
<?php
$values = get_post_custom_values("photoRSS");
// echo $values[0];
require_once 'rss_php.php';
$rss = new rss_php;
$item_limit = 3;
$rss->load($values[0]);
$items = $rss->getItems();
$i = 0;
$html = '';
foreach($items as $index => $item) {
if ($i < $item_limit) {
$html .= '<h3><a href="'.$item['link'].'" title="'.$item['title'].'">'.$item['title'].'</h3>';
$html .= '</a><br />'.$item['description'].'<br />';
$html .= "<br />;
$i++;
}
}
echo $html;
?>
Now all you need is to create a new page, using the photographs.php template.
In the Custom Fields, use custom field “photoRSS” tag and place the URL to your RSS feed and away you go!
Let me know what you think and what alternative you are using?
Hot Items From Amazon!
2 comments | 497 views
















Hi,
I’m hoping you can help me. I added to code to my page.php, but it errors on $html=”. just after the
$items = $rss->getItems(); My Safari web browser returns the following error:
Parse error: syntax error, unexpected ‘>’ in /home2/BronxImage/public_html/blog/wp-content/themes/freshblue-idea-10/page.php on line 35
Is that where you suggest adding code to make the box fancy. If so can you give an example? Your zenfolio feed looks great and I do want to add the same feature to my wordpress blog, but can’t get past the error.
Thanks
The error has to do with the PHP parsing. Check your syntax to make sure it is correct with proper opening and closing of tag. Use a PHP editor such as PSPad or something where it highlights the tags to ensure you have it properly closed.
If you copy and paste exactly as above, chances are the tag is missing something. It was difficult to post to HTML a code where the browser will read, so there might’ve been missing closing.
Did you properly open the tags?