Dear All,

I need to display RSS feed for each post, in below way : www.example.com/post-url-alias/feed

How to achieve this using post view, CONTEXTUAL FILTERS and path?

Comments

Jaypan’s picture

What is it you want to display in the node? An RSS feed is a list of things, but a node is only a single thing not a list.

Mradula.1990’s picture

In word press there is a feature called feed per post, in the same way I need to develop.

Jaypan’s picture

Ok, that doesn't answer my question though. Or maybe it would if I knew that feature, but I'm not a wordpress developer, and this isn't a wordpress forum, so it's probably best to assume that we don't know the feature you are referring to and/or how it works.

Mradula.1990’s picture

Rss feed per post.. Single Rss listing...

Jaypan’s picture

And again I ask, a listing of what? An RSS feed is a list of things. A node is only a single thing. What is it you want to list?

Mradula.1990’s picture

<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title></title>
	<atom:link href="https://example.com/post/feed/" rel="self" type="application/rss+xml" />
	<link>https://example.com/post/</link>
	<description>Today&#039;s data. Tomorrow&#039;s heathcare.</description>
	<lastBuildDate>Tue, 03 Jan 2017 18:09:53 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
</channel>
</rss>

in this way for each post. when i hit example.com/post/feed

Jaypan’s picture

Ok, I see what you want. I don't understand the rational behind wanting it, but that's beside the point.

The first thing you'll need to do is implement hook_menu:

function hook_menu()
{
  $menu['node/%node/feed'] = array
  (
    'title' => 'feed',
    'page callback' => 'feed_per_post_callback',
    'access callback' => TRUE, // allow access to anyone
  );

  return $menu;
}

Then you need to create the callback for the node:

function feed_per_post_callback($node)
{
  $output = array
  (
    '#theme' => 'feed_per_post_xml',
    '#node' => $node,
  );

  print render($output);
  drupal_exit();
}

Next, you'll need to implement hook_theme() to get the system to use the #theme you just referenced:

function hook_theme()
{
  return array
  (
    'feed_per_post_xml' => array
    (
      'variables' => array('node' => FALSE),
      'template' => 'feed-per-post-xml',
    ),
  );
}

This will allow you to create the template feed-per-post-xml.tpl.php, in which you can create the XML you showed above. The node will be available in your template as $node.