How to generate list of links from external WordPress Feed

Posted by: Alex on August 4, 2016

WordPress handily provides a RSS feed, usually at /feed/

This is accessible externally so it’s easy to use this data on external or local sites for simple link lists, scraping etc.
Here’s a really simple way to generate a li list of article headings along with their relevant link from an external WordPress feed.

Just replace the URL within the $feedURL variable to your desired feed.

  $feedURL = '';
  $rss = new DOMDocument();
  $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,
    array_push($feed, $item);
  $limit = 3;
  for($x=0;$x<$limit;$x++) {
    $title = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link = $feed[$x]['link'];
    echo '<li><a href="'.$link.'" title="'.$title.'">'.$title.'</a></li>';