How to display an RSS feed on your site or wordpress blog? How to display rss feed in HTML using PHP? Some times you may want to display the RSS feed of a popular news blog on your site. If you maintain multiple websites or blogs you can display the RSS feed of one site on another site. This will improve your sites visibility and page views.
To display an RSS feed and its content you need to create a Page and use the page to display the RSS Feed or you need to embed the PHP code in post or page or widget. As we discussed in earlier post ,usually wordpress won’t allow you to include PHP code in pots, page or sidebar. Read how to Insert, Execute, Embed or Include PHP Code in WordPress Post, Page or Sidebar.
Related:
- How to Display FeedBurner RSS Feed Subscriber Count As Text
- WordPress RSS Feed Fix: XML Parsing Error: XML or Text Declaration
There are two ways to display the RSS feed details on your blog page. You can either use the WordPress Feed API to fetch and parse the RSS feed or cURL and SimpleXML to retrieve and parse the RSS feed.
Display any External RSS Feed on Your Site using WordPress Feed API
You can display the RSS feed on any page. If you want to display on home page, you need to edit the home page template and add the code given below.
To display the RSS feed and content on a new page, you need to create a php file (“ExternalRSS.php”). (Read: How to create a custom page in wordpress blog) After creating the file add the below given code in that file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | <div style = 'display:block;width:500px;height:450px;border: 3px coral solid;'> <?php include_once(ABSPATH.WPINC.'/feed.php'); $rss = fetch_feed('http://feeds.feedburner.com/globinch'); $displayitems = $rss->get_item_quantity(5); $rss_items = $rss->get_items(0, $displayitems); ?> <ul> <?php if ($displayitems == 0) echo '<li>No items.</li>'; else foreach ( $rss_items as $item ) : ?> <li> <a href='<?php echo $item->get_permalink(); ?>' title='<?php echo $item->get_title(); ?>'> <b><?php echo $item->get_title(); ?></b></a> <br/> <?php echo 'Published On '.$item->get_date('j F Y | g:i a'); ?> <br/> <?php echo substr($item->get_description(), 0, 160) . '...'; ?> </li> <?php endforeach; ?> </ul> </div> |
In the above code replace “globinch” with your – feedburner id – if you are using a feedburner feed. Elase replace the complete URL with your RSS Feed URL.
The above code will be displayed as below.
- Fonts for Website :Top 10 Font Preview And Comparison Tools
Published On 8 May 2011 | 11:25 am
Online Free Font Preview and Compare services helps you to choose the best fonts for website. Many Font Comparison Tool not only help you to choose the right fo… - Top 10 Tools To Test Cross Platform Browser Compatibility
Published On 7 May 2011 | 8:09 pm
Cross Browser compatibility testing is one of the most important step before any website go live. Cross platform browser compatibility test is not a big deal if… - How To Display Twitter Followers Count as Text?
Published On 6 May 2011 | 5:17 pm
How To Display Twitter Follower Count as Plain Text? Some people do not want to display any fancy buttons to display Twitter Followers count or similar social n… - WordPress : Execute, Insert or Include PHP Code in Post, Page or Sidebar
Published On 6 May 2011 | 4:01 pm
How to insert PHP code in post or page? Some times it is necessary to embed or execute some PHP code in wordpress post, page or sidebar to display some dynamic … - WordPress Tips – How to Use WordPress Custom Page as Home Page
Published On 4 May 2011 | 6:52 pm
WordPress page templates and WordPress custom pages are easy to setup. WordPress can be customized to a great extend. One of such flexibility is to use a custom…
Display any External RSS Feed on Your Site Using PHP cURL and SimpleXML
PHP cURL is an API (libcurl) allows you to connect and communicate to many different types of servers with many different types of protocols. We can utilize the cURL and SimpleXML to display any RSS feed on your blog page. SimpleXML extension provides easy toolset to convert XML to an object that can be processed with normal property selectors and array iterators.
As mentioned above you can display the RSS feed on any page. If you want to display on home page or any other page, you need to edit the page template and add the code given below.
To display the RSS feed and content on a new page, you need to create a php file as mentioned above. (Read: How to Use WordPress Custom Page as Home Page) After creating the file add the below given code in that file.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | <div style = 'display:block;width:500px;height:450px;border: 3px coral solid;'> <ul> <?php $feedId = "globinch"; $stringVal=""; $url="http://feeds.feedburner.com/"; $url= $url. $feedId; $ch = curl_init(); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXMLElement($data,LIBXML_NOCDATA); echo "<strong><CENTER><h2>".$xml->channel->title. "</h2></h3>" . $xml->channel->description. "</h3></CENTER></strong>"; $cnt = 5; //This is for all items : count($xml->channel->item); for($i=0; $i<$cnt; $i++) { $url = $xml->channel->item[$i]->link; $title = $xml->channel->item[$i]->title; $date = $xml->channel->item[$i]->pubDate; $desc = substr($xml->channel->item[$i]->description, 0, 160) . '...'; echo '<li><span class="removed_link" title="'.$url.'">'.$title.'</span><br/>Published On: '.$date. '<br/>'.$desc.'</li>'; } ?> </div> |
This will be displayed as below.
- Fonts for Website :Top 10 Font Preview And Comparison Tools
Published On: Sun, 08 May 2011 11:25:45 +0000
Online Free Font Preview and Compare services helps you to choose the best fonts for website. Many Font Comparison Tool not only help you to choose the right fo… - Top 10 Tools To Test Cross Platform Browser Compatibility
Published On: Sat, 07 May 2011 20:09:53 +0000
Cross Browser compatibility testing is one of the most important step before any website go live. Cross platform browser compatibility test is not a big deal if… - How To Display Twitter Followers Count as Text?
Published On: Fri, 06 May 2011 17:17:35 +0000
How To Display Twitter Follower Count as Plain Text? Some people do not want to display any fancy buttons to display Twitter Followers count or similar social n… - WordPress : Execute, Insert or Include PHP Code in Post, Page or Sidebar
Published On: Fri, 06 May 2011 16:01:32 +0000
How to insert PHP code in post or page? Some times it is necessary to embed or execute some PHP code in wordpress post, page or sidebar to display some dynamic … - WordPress Tips – How to Use WordPress Custom Page as Home Page
Published On: Wed, 04 May 2011 18:52:41 +0000
WordPress page templates and WordPress custom pages are easy to setup. WordPress can be customized to a great extend. One of such flexibility is to use a custom…
Globinch
Tech-Knowledge that helps
Before you go, subscribe to get latest technology articles right in your mailbox!.
Your code is superb but the thing is after fetching all data from other site its not opening in my site instead of that its title redirecting the other site. I actually want when user click on title it will display full post in my site not redirect on other site. If there is a solution please provide me. Thanks in advance
Hi Bhupen,
It is possible, you need to edit the line no:24 where we add the anchor tag. You need to add the target attribute to the anchor tag. The target should be "_self".
Btw.. Many thanks for visiting my site and for the comments
Binu George
How we can get first image of each post?