Home Wordpress How to Fetch and Display RSS Feed in WordPress?

How to Fetch and Display RSS Feed in WordPress?

by therichpost
0 comment
How to Fetch and Display RSS Feed in WordPress?

Hello guys, welcome back to my blog. Today in this blog post, I am going to tell you, How to Fetch and Display RSS Feed in WordPress?

Working Demo
How to Fetch and Display RSS Feed in WordPress?
How to Fetch and Display RSS Feed in WordPress?
Rss Feed Data
Rss Feed Data

For WordPress lovers must check the below links for more WordPress knowledge:


Friends here is the working code snippet and please use this carefully to avoid the mistakes:

1. Firstly guys we need to add below code into our WordPress activated theme’s index.php file or any file:

<?php
$rss = new DOMDocument();
$rss->load('https://www.yoururl.com/rss/full');
$feed = array();
foreach ($rss->getElementsByTagName('item') as $node) {
    $item = array ( 
        'title' => $node->getElementsByTagName('title')->item(0)->nodeValue,
        'desc' => $node->getElementsByTagName('description')->item(0)->nodeValue,
        'link' => $node->getElementsByTagName('link')->item(0)->nodeValue,
        'date' => $node->getElementsByTagName('pubDate')->item(0)->nodeValue,
    'img' => $node->getElementsByTagName('enclosure')->item(0)->getAttribute('url')
        );
    array_push($feed, $item);
}
$limit = 3;
for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date = date('l F d, Y', strtotime($feed[$x]['date']));
  $image = $feed[$x]['img'];
  echo '<img src="'.$image.'"/>';
    echo '<p><strong><a href="'.$link.'" title="'.$title.'">'.$title.'</a></strong><br />';
    echo '<small><em>Posted on '.$date.'</
  em></small></p>';
    echo '<p>'.$description.'</p>';
}
?>

Guys here are some important rules to display RSS FEED on site to another:

  • All text from our RSS feeds must displayed as provided. Do not alter the content in any way.
  • You must ensure that all excerpts link directly to main website, using the link provided with post.
  • You may not sell, lease, sublicense, redistribute or otherwise monetize RSS feeds.

Now we are done friends. If you have any kind of query or suggestion or any requirement then feel free to comment below. There are lots of WordPress hooks and filters  and I will share into my future posts and we should use them rather then do custom code in theme core files or in plugins files.

Note: Friends, I just tell the basic setup and things, you can change the code according to your requirements. For better understanding must watch video above.
I will appreciate that if you will tell your views for this post. Nothing matters if your views will good or bad.

Jassa

Thanks

You may also like

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.