Jump to content

Embed RSS PHP code in Wordpress index.php to display feeds


RogerJH

Recommended Posts

I would like to display an RSS feed in a content element here: http://thepimmgroup.org/

In the box where it says "Coming soon" :)

 

When I add the PHP code to the index.php file, I'm getting errors with whichever method I have tried.

 

e.g., With the Simple Feed List WP plugin, I embed

<?php if (function_exists('simple_feed_list')) : ?>
<h2>TEST FEED</h2> <ul>
<?php simple_feed_list('feed://feeds2.feedburner.com/filehippo','5',''); ?></ul>
<?php endif; ?>

 

And get an error:

 

Warning: fopen(feed://feeds2.feedburner.com/filehippo) [function.fopen]: failed to open stream: No such file or directory in/home1/thepimmg/public_html/wp-content/plugins/simple-feed-list/simple-feed-list.php on line 41

 

And it just goes on to the next line with another error, then another, apparently caught in a loop.

 

If I try this code:

<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
$feed = fetch_rss('feed://feeds2.feedburner.com/filehippo'); // specify feed url
$items = array_slice($feed->items, 0, 7); // specify first and last item
?>

<?php if (!empty($items)) : ?>
<?php foreach ($items as $item) : ?>

<h2><a href="<?php echo $item['link']; ?>"><?php echo $item['title']; ?></a></h2>
<p><?php echo $item['description']; ?></p>

<?php endforeach; ?>
<?php endif; ?>

 

I get this error: Warning: array_slice() expects parameter 1 to be array, null given in /home1/thepimmg/public_html/wp-content/themes/ecogreen/index.php on line 79

BTW Line 79 reads:

$items = array_slice($feed->items, 0, 7);

 

With this code:

<?php
include_once(ABSPATH.WPINC.'/rss.php'); // path to include script
   $num_items = 10;
   $url = feed://news.google.com/news?q=biodiversity&output=rss;
   $rss = @fetch_rss( $url );
   $items = array_slice($rss->items, 0, $num_items);
  echo "<br />n<h4>" . $rss->channel['title'] . "</h4>";
   echo "<dl class="thepost">n";
   foreach ($items as $item) {
       $href = $item['link'];
       $title = $item['title'];
       echo "<dt><a href=$href>$title</a></dt>n";
   }
   echo "</dl>";
   ?>

 

The site breaks and I get an error: Parse error: syntax error, unexpected ':' in /home1/thepimmg/public_html/wp-content/themes/ecogreen/index.php on line 79. Line 79 is

$url = feed://news.google.com/news?q=biodiversity&output=rss;

(which is a valid feed).

 

So I'm kinda stuck. Can any of you PHP wizards please point me in the right direction?

 

Thank you!!!

 

Link to comment
Share on other sites

Personally I think feed2js is a better option as it does not slow down your servers execution time - when using feeds I always end up having to cache the files, as to increase loading time. But then again, it may not suite what your doing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.