Monday, February 20, 2012

Creating Rss Page for our site using our Content

Creating Rss Page for our site using our Content:

function rssfeed() {
  global $base_url;
  $sp_name = arg(2);
//(your content node id)
  $node_names = node_get_types('names'); //(your content type name)
  $title_name = $node_names[$sp_name] != '' ? $node_names[$sp_name] : $sp_name; 
  $query = "SELECT n.nid, n.type, n.title, nr.body, n.changed
    FROM {node} n
    JOIN {node_revisions} nr ON nr.nid = n.nid
    WHERE n.type = '%s'"; //(contents for the rss)
  $result = db_query($query, $sp_name);

//[ Creating Structure for rss Page ]
  header("Content-Type: application/rss+xml; charset=iso-8859-1");
  $rssfeed = '<rss version="2.0"> 
    <channel>
      <title>' . $title_name . '</title>';
  while($row = db_fetch_array($result)) {
    $nid = $row['nid'];
    $src = 'node/'.$nid;
    $url_alias = drupal_get_path_alias($src);
    extract($row);
    //encode description
    //$contenttitle = utf8_decode($title);
    //$contenttitle = str_replace('', '&trade;', $contenttitle);
    $contenttitle = html_entity_decode($title, ENT_QUOTES, "UTF-8");
    //$contenttitle = str_replace(array('&' , '®'), array('&amp;' , '&reg;'), $contenttitle);
    //encode description
    $contentdesc = html_entity_decode(strip_tags($body), ENT_QUOTES, "UTF-8");
   // $contentdesc = str_replace('&', '&amp;', $contentdesc);
    //Designing Each Rss
    $url = $base_url . '/'.$url_alias;
    $rssfeed .= '
      <item>
        <title>' .($contenttitle) . '</title>
        <description>' . check_plain($contentdesc)  . '</description>
        <link>' . $url . '</link>
        <pubDate>' . date("D, d M Y H:i:s O", $changed) . '</pubDate>
      </item>';
  }
  $rssfeed .= '
    </channel>
  </rss>';
  echo $rssfeed; //[Returning the rss structure]
}

6 comments:

  1. I have just implemented the given code for my fried website and it was successful. Thanks for sharing the code here.

    Drupal web developer

    ReplyDelete
  2. Magnificent items from you, man. I have realise your stuff preceding to and you are just too excellent. I really like what you have came by here, absolutely like what you are saying and the way in which you state it. You make it amusing and you still be careful of to hold it sensible. I can not delay to read far more from you. This is really a magnificent post.

    iphone app developer for hire | iphone custom development | Offshore Software Development Company

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. Hey, nice site you have here! Keep up the excellent work! ios developer

    ReplyDelete
  5. All RSS feed content is updated each time there is something new in target web page.
    Mobile Application Development Company

    ReplyDelete
  6. I have read this blog post It is easy and simple code for creating rss feed content Thanks for sharing!!
    Hire Angularjs Developers | Truck Dispatch Software | Taxi App Development

    ReplyDelete