ryan Posted February 24, 2011 Share Posted February 24, 2011 Given a PageArray of pages, this module will render an RSS feed from them. This is intended to be used directly from a template file. Installation Download the RSS feed module at the bottom of this message. To install, unzip and place the file in /site/modules/. Go into Admin > Modules and click "Check for new modules" at the bottom. Then click the "install" button for the "MarkupRSS" module. From there, you'll be able to configure several aspects of the module. Usage Create a template in ProcessWire and use the following example as a guide. See the actual .module file for more configuration options too. <?php // retrieve the RSS module $rss = $modules->get("MarkupRSS"); // configure the feed. see the actual module file for more optional config options. $rss->title = "Latest updates"; $rss->description = "The most recent pages updated on my site"; // find the pages you want to appear in the feed. // this can be any group of pages returned by $pages->find() or $page->children(), etc. $items = $pages->find("limit=10, sort=-modified"); // send the output of the RSS feed, and you are done $rss->render($items); This module is now included in the ProcessWire core. 2 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted February 24, 2011 Share Posted February 24, 2011 great! I need it a lot , i will try immediatly ;D Link to comment Share on other sites More sharing options...
Frank Vèssia Posted March 1, 2011 Share Posted March 1, 2011 I used for two website and i cannot find any fault, it's perfect and easy to use, maybe you can add a function to cut some long text in itemDescriptionField because sometimes i could not have a summary text in my template in addition to body field and for feed it's good to have small text, but this is not a big problem. Link to comment Share on other sites More sharing options...
ryan Posted March 1, 2011 Author Share Posted March 1, 2011 Thanks for your feedback. I've added an option to limit the length of the item description field. You can now set this in the module config screen. It will attempt to truncate to the closest punctuation within your max length, or at the closest space if no punctuation is close by. If you download the current ZIP file attached to the original message, that will have it (MarkupRSS-module3.zip). Link to comment Share on other sites More sharing options...
apeisa Posted March 2, 2011 Share Posted March 2, 2011 This is great news and great to get more well coded and commented examples to help module development. Haven't tried yet, but if I read correctly it should be trivial to create normal template, but add in top check if $input->get->format == rss and render rss instead of normal template. Show we could get urls like: www.domain.com/news/ (normal news listing) and www.domain.com/news/?format=rss (rss feed). Other way to handle rss for whole site would be one rss-template: www.domain.com/rss/?page=321 or www.domain.com/rss/?template=news etc... I think after little testing this should come with processwire as default module (or do we call them core modules?). Link to comment Share on other sites More sharing options...
ryan Posted March 2, 2011 Author Share Posted March 2, 2011 Thanks, glad you like it so far. The examples you mentioned should work well. Though I would probably recommend using URL segments rather than GET vars, so that the template output can be cachable. (GET vars aren't cachable at the template level). For example, lets say that domain.com/news/ is a page that lists an index of the latest news items. In your template, you could have it detect a URL segment "rss", so that domain.com/news/rss/ displays an RSS version of it instead: <?php if($input->urlSegment1 == 'rss') { // display the RSS feed $rss = $modules->get("MarkupRSS"); // ... $rss-render($page->children("limit=10")); } else { // display the regular news list template output include("./news-list.php"); } I agree that this should probably be a core module (/wire/modules/) so I will add it to the source and include an RSS feed example in the default site profile. Link to comment Share on other sites More sharing options...
apeisa Posted March 2, 2011 Share Posted March 2, 2011 Thanks, glad you like it so far. The examples you mentioned should work well. Though I would probably recommend using URL segments rather than GET vars, so that the template output can be cachable. (GET vars aren't cachable at the template level). This is good to know and thanks for clarification. So if I have any GET vars then template is never cached? Link to comment Share on other sites More sharing options...
ryan Posted March 2, 2011 Author Share Posted March 2, 2011 The template will be cached, but it might never have an opportunity to see the GET vars (except when regenerating the cache). Since the output is cached, it would deliver cached output and your code that looks at the value of a GET or POST var would only run when the cache is rebuilt. This is why I usually leave off template caching for any pages that need to examine GET, POST, COOKIE or SESSION vars. Examples would be search engines, forms, etc. Btw, the template cache is always off when you are logged in. Template caching is applicable only to anonymous users visiting the site. The reason why ProcessWire doesn't cache GET vars is because there is an infinite number of them possible. We don't want to make it possible for someone to fill up your hard drive with a million different cached variations of the same page with different GET vars. On the other hand, ProcessWire will cache up to 999 URL segments or page numbers, for each page that is using them (when enabled for it's template). However, unless your page is slow to render, it's simpler just to leave off template caching when pages using it need to generate different output according to the request. Link to comment Share on other sites More sharing options...
Frank Vèssia Posted June 24, 2011 Share Posted June 24, 2011 hey Ryan, i'm using this module but now i need to change the title of each item to a custom title composed by the title of the page + a custom fixed text. Now i'm using: $rss->itemTitleField = "title"; i would like to do something like => title+'my text'; Thanks Link to comment Share on other sites More sharing options...
ryan Posted June 24, 2011 Author Share Posted June 24, 2011 You can modify the titles of the items before sending them to $rss->render: <?php // retrieve the RSS module $rss = $modules->get("MarkupRSS"); // configure the feed. see the actual module file for more optional config options. $rss->title = "Latest updates"; $rss->description = "The most recent pages updated on my site"; // find the pages you want to appear in the feed. // this can be any group of pages returned by $pages->find() or $page->children(), etc. $items = $pages->find("limit=10, sort=-modified"); // add something to the item titles foreach($items as $item) { $item->title = $item->title . " my text"; } // send the output of the RSS feed, and you are done $rss->render($items); 1 Link to comment Share on other sites More sharing options...
Frank Vèssia Posted June 24, 2011 Share Posted June 24, 2011 thanks Link to comment Share on other sites More sharing options...
neildaemond Posted December 1, 2011 Share Posted December 1, 2011 I was just wondering if this module supports more than 1 rss feed per template. ie, could i do something like this? $rss = $modules->get("MarkupRSS"); $rss2 = $modules->get("MarkupRSS"); $rss3 = $modules->get("MarkupRSS"); ... Link to comment Share on other sites More sharing options...
ryan Posted December 1, 2011 Author Share Posted December 1, 2011 Yes, you can do that. This is what's called a 'singular' module, meaning it returns a new instance on every $modules->get("MarkupRSS"). So you can create as many instances as you need, and they don't share data with each other. Link to comment Share on other sites More sharing options...
neildaemond Posted December 1, 2011 Share Posted December 1, 2011 thanks! my guess was yes.. but didn't want to have to find out the hard way~ ...oh, and someone else might be wondering too (btw, only taking 1.5hrs to reply my post is quite amazing!) Link to comment Share on other sites More sharing options...
Soma Posted December 1, 2011 Share Posted December 1, 2011 (btw, only taking 1.5hrs to reply my post is quite amazing!) Hold on ... , usually he's much faster! ;D Link to comment Share on other sites More sharing options...
neildaemond Posted January 1, 2012 Share Posted January 1, 2012 My RSS Feeds seem to only show the title of the Item ( I used the above mentioned code to modify the title of the items). I noticed in MarkupRSS.module that the $defaultConfigData array has itemDescriptionField => 'summary' My pages don't have a summary field. Is there a way to make my RSS feed show more than just a title? ie some of the $body? I tried changing the module code to itemDescriptionField => 'body' but it didn't work. Also, I edited the module without reloading it anyhow, could that have made it not work? thanks, Link to comment Share on other sites More sharing options...
Marty Walker Posted January 2, 2012 Share Posted January 2, 2012 Hi, I tend to use more than just the body in my pages so I code my own (http://www.smd.net.au/rss/). It outputs the body and then my project images which matches the order on my site. Here's what it looks like: <?php header('Content-Type: application/rss+xml; charset=utf-8'); ?> <?php echo "<?phpxml version=\"1.0\" encoding=\"utf-8\"?>\n"; ?> <rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom"> <channel> <title>stillmovingdesign</title> <link>http://www.smd.net.au/rss</link> <description>RSS Feed</description> <?php $featured = $pages->get("/work/")->find("template=work, sort=sort, limit=999"); foreach($featured as $feature) { $image = $feature->images->first(); $h = $image->height(); $w = $image->width(); $thumb = $image->size(310,0); echo "<item>\n<title>{$feature->title}</title>\n<link>http://www.smd.net.au{$feature->url}</link><dc:creator>stillmovingdesign</dc:creator><guid isPermaLink=\"false\">http://www.smd.net.au{$feature->url}</guid>"; echo "<description><![CDATA["; echo "<p>" . $feature->summary . "</p>"; foreach($feature->images as $featuredimages) { $large = $featuredimages->width(650); echo "<img src='http://www.smd.net.au{$large->url}' title='{$feature->title}' alt='{$feature->title}' />\n"; } echo "{$feature->body}"; echo "]]></description>\n"; echo "</item>\n\n"; } ?></channel></rss> As an aside I use twitterfeed to automatically tweet each job I publish to Twitter. It works really well. Regards Marty 1 Link to comment Share on other sites More sharing options...
ryan Posted January 2, 2012 Author Share Posted January 2, 2012 My RSS Feeds seem to only show the title of the Item ( I used the above mentioned code to modify the title of the items). I noticed in MarkupRSS.module that the $defaultConfigData array has The item description field is actually configurable in the module settings. In the admin, go to Modules > Markup > RSS. Click on it to configure the various settings it can use. This sets the defaults for all instances of MarkupRSS. If you prefer, you can also change the settings at runtime for any individual instance like this: <?php $rss = $modules->get('MarkupRSS'); $rss->itemDescriptionField = 'body'; echo $rss->render($yourPages); Also, thanks for the great example stillmovingdesign! Link to comment Share on other sites More sharing options...
neildaemond Posted January 3, 2012 Share Posted January 3, 2012 Works like a charm, Thanks Ryan! Link to comment Share on other sites More sharing options...
PHPSpert Posted January 27, 2012 Share Posted January 27, 2012 I noticed that itemDescriptionField gets tags stripped. It would be great if this was a boolean option for this. I usually set up my blog(or other RSS feeds) to show the full article so anyone can view the entire thing in their reader. Link to comment Share on other sites More sharing options...
ryan Posted January 27, 2012 Author Share Posted January 27, 2012 Clinton, I've updated the module to support this. You'll find it in the latest commit in the PW 2.2 source. To enable, specify '0' as the max length for the description field in the module settings. Can you confirm that this solves the issue and enables use of the full article? Thanks, Ryan 1 Link to comment Share on other sites More sharing options...
PHPSpert Posted January 27, 2012 Share Posted January 27, 2012 Thanks Ryan, It's working great! Link to comment Share on other sites More sharing options...
ryan Posted January 29, 2012 Author Share Posted January 29, 2012 Thanks for reporting back. Glad to hear it's working how it should. Link to comment Share on other sites More sharing options...
Samuel Posted April 14, 2013 Share Posted April 14, 2013 I am just trying to retrieve the rss feed and I am getting this error, when opening the page, with the template containing the following rss code. This page contains the following errors:error on line 1 at column 2: StartTag: invalid element nameBelow is a rendering of the page up to the first error. Where as "below" nothing appears. The Code: <?php // retrieve the RSS module $rss = $modules->get("MarkupRSS"); // configure the feed. see the actual module file for more optional config options. $rss->title = "Latest updates"; $rss->description = "The most recent pages updated on my site"; // find the pages you want to appear in the feed. // this can be any group of pages returned by $pages->find() or $page->children(), etc. $items = $pages->find("tags=short"); // send the output of the RSS feed, and you are done $rss->render($items); Any ideas, what I am doing wrong? Link to comment Share on other sites More sharing options...
adrian Posted April 14, 2013 Share Posted April 14, 2013 Does it work with a more standard: $items = $pages->find("limit=10, sort=-modified"); Also, what do you see if you view the page source - it might show the start of the xml so you can see the tag problem. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now