user1597438
user1597438

Reputation: 2231

Zend_Feed_Rss Manipulation for Magento newsfeed

I have created a newsfeed in my magento site using Zend Framework. This works almost perfectly except, I want to retrieve only the first 3 entries on the rss. If I try to do this, the first 3 items are displayed on my site but the foreach loop continues to execute so excess spaces and html elements are added in my site. How can I retrieve only the first 3 entries of the rss? Here's how my code looks:

<?php $i = 0;
<?php $channel = new Zend_Feed_Rss('http://mydomain/newsfeed'); ?>
<?php foreach ($channel as $item): 
<div>
if($i<3): ?>
    <label>My feed title is: <?php echo $item->title; ?>
<?php endif; $i = $i + 1; ?>
</div>
<?php endforeach; ?>

I have about 10 entries on the newsfeed so if I execute something like this, I get the first 3 properly, then I get 7 excess labels with My feed title is:. I tried, using break but this broke my entire page so I can't use that. Can someone please guide me to the right direction?

Upvotes: 0

Views: 292

Answers (1)

liyakat
liyakat

Reputation: 11853

you can try with for loop instead of foreach

for($i=0; $i<=min(3, count($channel->title)); $i++) {   
  $feed_title = $channel->title[$i];
  // do something
}

hope this will sure solve your issue.

Upvotes: 1

Related Questions