How to include an RSS feed or search results on a single template?
-
I am using Custom Post Types, so the title of each post is the name of a restaurant. On each single-restaurant.php I wan to also include a list of related news from our site related to this restaurant.
I think the easiest ay is to show a list of the search results via RSS. So I have this code:
<?php include_once(ABSPATH.WPINC.'/feed.php'); $rss = fetch_feed('https://www.website.com/search/'.the_title()'/feed'); $maxitems = $rss->get_item_quantity(5); $rss_items = $rss->get_items(0, $maxitems); ?> <ul> <?php if ($maxitems == 0) echo '<li>No items.</li>'; else // Loop through each feed item and display each item as a hyperlink. foreach ( $rss_items as $item ) : ?> <li> <a href='<?php echo $item->get_permalink(); ?>' title='<?php echo 'Posted '.$item->get_date('j F Y | g:i a'); ?>'> <?php echo $item->get_title(); ?></a> </li> <?php endforeach; ?> </ul>
But I am getting errors on the fetch_feed where I am trying to call the_title. Any idea how to fix this to make it work? I know thee are plugins that show related news, but I wan to hardcode this code into the theme without using a plugin.
Viewing 3 replies - 1 through 3 (of 3 total)
Viewing 3 replies - 1 through 3 (of 3 total)
- The topic ‘How to include an RSS feed or search results on a single template?’ is closed to new replies.