• Resolved adowdle

    (@adowdle)


    I am having a problem with the code given here for RSS feeds.

    <?php // Get RSS Feed(s)
    include_once(ABSPATH . WPINC . '/rss.php');
    $rss = fetch_rss('http://example.com/rss/feed/goes/here');
    $maxitems = 5;
    $items = array_slice($rss->items, 0, $maxitems);
    ?>
    
    <ul>
    <?php if (empty($items)) echo '<li>No items</li>';
    else
    foreach ( $items as $item ) : ?>
    <li><a href='<?php echo $item['link']; ?>'
    title='<?php echo $item['title']; ?>'>
    <?php echo $item['title']; ?>
    </a></li>
    <?php endforeach; ?>
    </ul>

    The site I am working on pulls an RSS feed from a calendar site; when the feed is empty, I want to display a message instead. This displays the RSS feed properly when it points to a feed w/content, but it does not display the message when the feed is empty.

    I would welcome *any* suggestions!

Viewing 5 replies - 1 through 5 (of 5 total)
  • It works for me, i’ve just plonked that into a theme on my test install, right in the header file and pointed it to an empty category feed at my website, i received the “No Items” message as expected…

    Am i missing something?

    What about using if(count($items) < 1) instead of if(empty($items))?

    Just a thought…

    Both should work…

    I can’t replicate the problem though, it worked straight off.. 🙁 …

    I’d imagine counting is slower then checking if empty… (by milliseconds, lol) .. i’d stick with the if empty… 😛

    Thread Starter adowdle

    (@adowdle)

    (count($items) < 1) fixed it, thanks! 😀

    How ironic, i’ll eat my words… 🙂

    ** yum yum **

    Perhaps someone with access to the codex could update the page to use count instead..

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘Display Message when RSS feed is empty’ is closed to new replies.