Array_Slice error when trying to RSS feed sites own comments
-
Hi there,
When I try to use the below code to get the 5 latest comments, I get this error :
Warning: array_slice() [function.array-slice]: The first argument should be an array in /home/site/www/wp-content/themes/default/sidebar.php on line 123
Code :
<li> <h2>Last 5 Comments On </a></h2> <?php // Include the RSS functions of wordpress include_once(ABSPATH . WPINC . '/rss.php'); // Grab my RSS feed $feed = fetch_rss("<?php bloginfo('comments_rss2_url');>"); // I want 5 results please $maxitems = 5; $items = array_slice($feed->items, 0, $maxitems); // Output the results! if(!empty($items)) { echo '<ul>'; foreach ($items as $item) { echo '<li>'; echo '<a href="'; // This is a bit messy, but it makes the output valid XHTML strict by removing ampersands $item['link'] = str_replace("&", "&", $item['link']); $item['link'] = str_replace("&&", "&", $item['link']); // End of messyness. Output the link echo $item['link']; echo '">'; // Output the title echo $item['title']; echo '</a>'; // If i've written a description, output it if (isset($item['description'])) { echo '<br />'; echo $item['description']; } echo '</li>'; } echo '</ul>'; } ?>
The frustrating thing is : when I put another RSS feed into the fetch_rss location field, it works just fine.
Directly inputting the /sites/comment/feed address into the fetch_rss location field also does not work. Same error.
Going with Firefox to /site/comments/feed works just fine.
This happens whether or not I have the Feedburner FeedSmith plugin turned on.
As a side note, how can I reduce the number of characters returned to say, 50?
Thanks VERY much for your help on this, I really need assistance here.
Line 123 is BTW –
$items = array_slice($feed->items, 0, $maxitems);
- The topic ‘Array_Slice error when trying to RSS feed sites own comments’ is closed to new replies.