Jump to content
ryan

RSS Feed Module

Recommended Posts

Dear Ryan,

> Now if the page pointed to by "custom_template_file" is hidden, that doesn't matter, because that's a page you are using to match,

> not one of the pages being returned by find().

I think I understand the above. The find command is finding pages that are not hidden: it's just the selector values that are hidden, but I'm not trying to display those hidden selectors; I'm just using them to match non-hidden pages.

In any case, the selector values won't be accessible as pages, so that's good.

Thanks for your help on this.

Peter

  • Like 1

Share this post


Link to post
Share on other sites

First let me say that PW is like a breath of fresh air. I'm hooked. Maybe a very noob question but,

I have copied into the site modules folder and modified this (RSS Feed) module in order to include more fields in the description. That worked like a charm but

now I want to add a stylesheet to it. The path never seems to work. Relative, absolute, all types of $config variables and "hard codes".

I added it to the $defaultConfigData array and tried editing line 90 to create the '<?xml-stylesheet' element with a hard coded 'href='. Is there maybe something

I'm missing ?

Share this post


Link to post
Share on other sites

I never tried this, but by looking at the module it appears that this would work:

// if using Ryan's example:

$rss = $modules->get("MarkupRSS"); 
$rss->title = "Latest updates";
$rss->description = "The most recent pages updated on my site";
$rss->css = "{$config->urls->templates}styles/rss.css"; // <- here goes the css url
$items = $pages->find("limit=10, sort=-modified");
$rss->render($items); 

edit: oh, and welcome :)

edit2: changed $config->path->templates to $config->urls->templates. Thxs for finding this Soma

Share this post


Link to post
Share on other sites

I tried that. I'm on the dev branch. Maybe it's a bug. Thanks for the quick attention. Being stuck is torture. I dream of Porto.

Share this post


Link to post
Share on other sites

Actually it makes sense that it doesn't work because it's a private property. Sorry for that...

There's a "default link to css stylesheet" in the module's configuration options, did you try that?

The weather is very unpleasant here for the moment, you should dream of other places :)

Share this post


Link to post
Share on other sites

Shouldnt it be $config->urls->templates ...?

Path is for php and file system.

  • Like 1

Share this post


Link to post
Share on other sites

of course... thanks Soma

Share this post


Link to post
Share on other sites

I never tried this, but by looking at the module it appears that this would work:

// if using Ryan's example:

$rss = $modules->get("MarkupRSS"); 
$rss->title = "Latest updates";
$rss->description = "The most recent pages updated on my site";
$rss->css = "{$config->url->templates}styles/rss.css"; // <- here goes the css url
$items = $pages->find("limit=10, sort=-modified");
$rss->render($items); 

edit: oh, and welcome :)

edit2: changed $config->path->templates to $config->url->templates. Thxs for finding this Soma

Diogo,

Small typo: $config->url->templates should be $config->urls->templates - you are missing the "s" :)

  • Like 1

Share this post


Link to post
Share on other sites

I did try that . First I tried the "module's configuration options". Then tried it in "$defaultConfigData" in the module, and then tried replacing "$this->css" in

the function "renderHeader" in the module. I tried every $config variable that I thought applied and then with the full local url to the style folder. Nothing.

It's the first time I have opened up a module and wondering if I'm missing something basic.

Thanks again all.

Aahh ... but here in Vienna it's been like spring in Greenland ... a rainy Porto is still better to me.

Share this post


Link to post
Share on other sites
Actually it makes sense that it doesn't work because it's a private property. Sorry for that...

It's not a private property. You can set it via $rss->css = '...';

This property can also be set from the module configuration screen.

I think the problem here is that it looks like you guys are setting it without an http host. $config->urls properties don't have host names in them, and an RSS feed would probably need a host name in it. I'm thinking this would work?

$rss->css = 'http://' . $config->httpHost . $config->urls->templates . 'styles/rss.css';

Share this post


Link to post
Share on other sites

but ... in the renderHeader function in the module when I add the actual url to my css file ( without any variables ) and concat it to $out ( so ... no "if($this->css)" ) I still get no css requests showing up in the firebug net tab. Wouldn't, at that point, a failed request be showing up if it was just that the url was wrong? 

Share this post


Link to post
Share on other sites

Admittedly it's been awhile since I've tried styling an RSS feed, so don't consider myself an expert on that at the moment. I think the css property was added there at the request of someone else, because I've always used an XSL file linked in the RSS feed, in the past. But you can see if it's ending up in the feed just by viewing the source of the feed. Still I'm wondering if maybe you really want to use an XSL file rather than an CSS file?

Example (though in PW1): 

RSS feed that links to XSL file:

http://www.nanotechproject.org/news/rss/

XSL file links to CSS file:

http://www.nanotechproject.org/process/templates/styles/rss_feed.xsl

CSS file that styles feed: 

http://www.nanotechproject.org/process/templates/styles/rss_feed.css

Share this post


Link to post
Share on other sites

Thanks Ryan!! The advice was perfect.

Share this post


Link to post
Share on other sites

Hallo!

Apparently you could only choose between "created" and "modified" for the "Default Feed Item Date Field".
Could you make it more flexible, so that any field could be used there?

In lots of cases the client woul'd like to transfer existing bolg-posts to the new web-site, and we do copy the content into the Processwire, but the "create" and "modify" don't mean anything any more.


Regards!!

Share this post


Link to post
Share on other sites
Apparently you could only choose between "created" and "modified" for the "Default Feed Item Date Field".

Could you make it more flexible, so that any field could be used there?

There isn't any dependency on 'created' or 'modified'. You can use any date field you want to. In fact, most of the time I use a custom date field for this. However, you have to specify it when you render your feed. The one that you set in the module settings is only the default value that takes effect if you don't override it when rendering your RSS feed. 

Share this post


Link to post
Share on other sites

Hey guys, 

I'm having a problem with rendering an rss feed of the current pages children.  It simply doesn't render any items when I use $page->children.  However when I use the provided sample of $items = $pages->find('sort=-modified, limit=10'); it displays them all fine. I've checked and my selector does return results so I'm not sure what's going on. 

My code: 

<?php 
$rss_feed_segment = 'rss';

if (strtolower($input->urlSegment1) == $rss_feed_segment ): 
    $modules->get('Spex')->setBaseLayout('_rss');

    // 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.
    $news_items = $page->children;

    // send the output of the RSS feed, and you are done
    $rss->render($news_items);

endif;  

The output: 

<?xml version='1.0' encoding='utf-8' ?>
<rss version='2.0'>
<channel>
	<title>Latest updates</title>
	<link>http://courts.dev/court/news/</link>
	<description>The most recent pages updated on my site</description>
	<pubDate>Mon, 21 Oct 2013 12:13:14 -0400</pubDate>
	<ttl>60</ttl>
</channel>
</rss>

I've never worked with with RSS feeds before so I may just be missing something simple.  

Thanks for any help!

Share this post


Link to post
Share on other sites

You need to define the page to get the children from. If you have that code in an rss.php file, then $page refers to that page. You need it to refer to the page that is the parent of the items you want to get, so try something like:

$news_items = $pages->get(selector to get parent)->children();

PS Welcome to the forums :)

Share this post


Link to post
Share on other sites

I have an rss feed that searches for pages with today's date (day and month).

    $todayday = date("d");
    $todaymonth = date("m");

    $features = $pages->find("parent=/events/, bfd_day.name=$todayday, bfd_month.name=$todaymonth, sort=bfd_year");

Is there a way to have the feed go out once every day, say at 2.00 am?

And, can someone direct me towards formatting the feed, or is this dependent on the reader used?

    $feedtxt = "<li>
    <table><tr><td width='200' valign='bottom'>
    <div style='max-width:200px'>
	<img src='{$webimage}' align='right' style='width:100%; height:100%'>
	</div></td><td width='15'></td><td valign='bottom'>
	<span class='nobelbold_32px'>{$feature->bfd_case->title}</span><span class='nobelbold_24px_grey'><br>{$yearsago}<p style='line-height: 18px; margin: 0 !important;'></span><span class='nobelregular_18px_grey'><a href='{$feature->url}'>{$datetxt}</a><br><br>{$sanitizer->textarea($feature->bfd_text_before, $options = array('allowableTags' => '<a>, <em>, <strong>'))} {$ageoldtxt}{$nametxt} {$eventtxt}{$atagetxt} in {$placetxt}.<br>{$extratxt}</span></p></li></td></tr></table><hr>";

For instance, in Firefox the images don't scale, in Vienna RSS reader they do but none does any formatting except <em> , <b>, etc. The css url points to the CSS stylesheet used for other templates on the site.

Share this post


Link to post
Share on other sites

Thanks for this! I'm trying to list unpublished items in an RSS feed for moderators to keep track on new items. Can't seem to get "status=unpublished" to render any results when I use it in the RSS template, though. Works fine for other templates. Any idea?

Share this post


Link to post
Share on other sites

RSS is not meant for unpublished pages!

#157

foreach($this->feedPages as $page) {
    if(!$page->viewable()) continue;
    $out .= $this->renderItem($page);
}

Why not just simply create your own xml list? Or copy the RSS module to your site/modules and rename/modify it to your need.

Share this post


Link to post
Share on other sites

Why not just simply create your own xml list?

Ahum, as if we are 'simply' capable of doing so, while still wrestling to get ProcessWire under my thumb....

Share this post


Link to post
Share on other sites

Ahum, as if we are 'simply' capable of doing so, while still wrestling to get ProcessWire under my thumb....

As if I could know you are not capable of doing things that require some coding when doing things that are not covered by ProcessWire.

As for your question above, I really don't know as I don't understand how a RSS feed is getting sent? I usually serve a RSS XML Feed url that people subscribe to so there seems to be no "send out"? But I see there's a TTL for the feed settings, which as far as I know is the interval a reader is meant to update the feed, but there's no "at that hour" setting in a RSS feed as little as I know.

And, can someone direct me towards formatting the feed, or is this dependent on the reader used?

The RSS module supports XSL stylesheet as far as I know. But it doesn't support custom content for the description field. I have never done RSS feeds that are styled or contains more than the standard "description" text. I guess it depends on what readers are capable of, similar to Newsletters. I usually try to avoid it, so I can't help there. https://www.google.ch/#q=formatting+rss+feeds

As far as Custom content goes there could be a simple trick to feed the RSS module description "itemDescriptionField" (default "summary") field used with custom content.

Before the RSS creation code in the template, you could define a local hook to add a new custom property to Page.

// hook to add new property to pages, this makes $page->customDescription return some formatted code;
wire()->addHookProperty("Page::customDescription", null, "customDescription");

function customDescription($event){
    $page = $event->object;
    $event->return = "<h1>$page->title</h1><p class='lead'>$page->summary</p><img src='{$page->image->url}'>";
}

// RSS generation using the above customDescription "field"
$feed = $modules->MarkupRSS;
$limit = 20;
$articles = $pages->find("template=post, sort=-date_published, limit=$limit");
$feed->itemDescriptionField = "customDescription";$feed->render($articles);

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...