Views2 — How do RSS Theming?
konopko - December 20, 2008 - 13:35
Hi!
I need use theming for my RSS feed. I wand use not only "Row style: Node", but get RSS titles by combining with few items ([RSS title] = [Category name] + [Child node name]).
How do that?
Thanks
P.S. I'm use Views 2.1.

Up
Up
Up
Up
I've install new Views
I've install new Views 6.x-2.2 and try to make theming for my feed.
My template is "views-view-row-rss--frontpage--feed-1.tpl.php" and its content like that:
<item><title><?php print $title; ?></title>
<link><?php print $link; ?></link>
<description><?php print $description; ?></description>
<?php print $item_elements; ?>
</item>
How can I get current node id, for example ($nid variable is not avalible) ?
The only way I've been able
The only way I've been able to figure this out is by dropping this in the template file:
$nid = $variables['view']->result[0]->nid;
Feels a bit hacky though.
--
My personal blog - http://scotthadfield.ca
I also work for NowPublic
Its cool, but how do I know
Its cool,
but how do I know the feedline_index for "$nid = $variables['view']->result[feedline_index]->nid;" ?
Some decision
As result we have follow structure:
stdClass::__set_state(array('title' => '…',
'link' => '…',
'elements' => array (
0 => array ( 'key' => 'pubDate', 'value' => 'Fri, 26 Dec 2008 08:02:17 +0000', ),
1 => array ( 'key' => 'dc:creator', 'value' => '…', 'namespace' => array ( 'xmlns:dc' => 'http://purl.org/dc/elements/1.1/', ), ),
2 => array ( 'key' => 'guid', 'value' => '51 at http://….com', 'attributes' => array ( 'isPermaLink' => 'false', ), ),
),
'description' => '',
))
To extract node id (in that example nid=51) from the structure I used next code:
$str = '';
$i = 0;
$nid = '';
while (true):
$str = substr($row->elements[2][value], $i, 1);
if ($str <> ' '){
$nid = $nid . $str;
} else {
break;
}
$i = $i +1;
endwhile;
hack the view RSS plugin
I'm sure this is not a best solution but could solve lot of headache on custom RSS feed creation.
When you are on the theming it's too late. The rss view plugin (views_plugin_row_node_rss.inc) load the node but doesn't pass this value to the theme itself:
<?php
function render($row) {
// For the most part, this code is taken from node_feed() in node.module
global $base_url;
$nid = $row->{$this->field_alias};
if (!is_numeric($nid)) {
return;
}
$item_length = $this->options['item_length'];
if ($item_length == 'default') {
$item_length = variable_get('feed_item_length', 'teaser');
}
// Load the specified node:
$node = node_load($nid);
?>
So here we have the node! After this line we process the node trough various "hooks":
$node->build_mode = NODE_BUILD_RSS;$node = node_invoke($node, 'view', $teaser, FALSE);
node_invoke_nodeapi($node, 'view', $teaser, FALSE);
$content = drupal_render($node->content);
node_invoke_nodeapi($node, 'alter', $teaser, FALSE);
$extra = node_invoke_nodeapi($node, 'rss item');
Then set the $item->description from $node->body;
So at the end you can use the 'alter' hook to change the $node->body (or $node->teaser).
The problem is all this 'hooks' are not context-aware. This means that if you write your code this apply to all the node rendered for any RSS view. I.e. you can not, says, inject different cck themed field in the body for different feeds.
A simple (and hacky) solution could be pass the node object itself to the $item so you can use at theme level. You can have different theme (i.e. different tpl.php) called for different (views generated) feed using different node parts.
On the $item object creation:
<?php$item = new stdClass();
$item->title = $node->title;
$item->link = url("node/$row->nid", array('absolute' => TRUE));
?>
Add the line:
<?php$item->node = $node;
?>
And have fun on the template using $item->node object: you have all the field themed (you can use 'safe' or 'view').
If your need only to theme images you can check the MediaRSS
Un'altra Pavia e' possibile
www.bitvark.it - www.kronstadt.it - www.mupa.it
This is excellent! Too bad
This is excellent! Too bad this cant be included by default.
Can you give me an example of how to call on the title using the $item->node object? I cant seem to get the syntax right.