Question

I have some PHP code that displays my RSS items, which i have limited to 1. I would like to make the code cycle through my RSS items with a fade in out effect. I can probably work out the jQuery for the fade, but getting it to cycle is my main issue.

<?php
$rss = new DOMDocument();
$rss->load('http://www.huffingtonpost.com/feeds/news.xml');
$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 = 1;
for ($x = 0; $x < $limit; $x++) {
    $title       = str_replace(' & ', ' &amp; ', $feed[$x]['title']);
    $link        = $feed[$x]['link'];
    $description = $feed[$x]['desc'];
    $date        = date('l F d, Y', strtotime($feed[$x]['date']));
    echo '<br><p><strong><a href="' . $link . '" title="' . $title . '">' . $title . '</a></strong><br>' . $description . '</p>';
}
?>
Was it helpful?

Solution

It's a simple issue, your $limit is static and set to 1. To find the number of array values, use count():

$limit = count($feed);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top