Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I Just need some correct results from 6 rss feed I am fetching 6 feeds and maked a news ticker bar at http://thehoopdoctors.com/online2/newfeed/

I am getting results from 6 rss feeds like First getting all posts from http://thehoopdoctors.com/online2/newfeed/", Then All "http://thepigskindoctors.com/newfeed/", Then All "http://thepuckdoctors.com/newfeed/", Then All "http://thecagedoctors.com/newfeed/", Then All "http://thedugoutdoctors.com/newfeed/", Then All "http://videogoneviral.com/newfeed/"

I just need get one by one.

I just need to get post from all urls one bye one like "http://thepigskindoctors.com/newfeed/", first post "http://thepuckdoctors.com/newfeed/", first post and so on.

my code is

<?php

$rsslist=array(
"http://thehoopdoctors.com/online2/newfeed/",
"http://thepigskindoctors.com/newfeed/",
"http://thepuckdoctors.com/newfeed/",
"http://thecagedoctors.com/newfeed/",
"http://thedugoutdoctors.com/newfeed/",
"http://videogoneviral.com/newfeed/"
);
$feed = fetch_feed($rsslist);
?>


<ul id="news-ticker" style="float: left;height: 15px !important; margin-left: 2px; margin-top: 10px; overflow: hidden; position: relative;width: 500px;">
<?php
foreach($feed->get_items() as $item) {?>
<li class="news"><a style="color:white !important;" href="<?php echo $item->get_permalink();?>"><?php echo $item->get_title();?></a></li>
<?php }?>
</ul>
share|improve this question

1 Answer 1

up vote 0 down vote accepted

What you're looking for is probably something along the lines of:

<ul id="news-ticker" style="float: left;height: 15px !important; margin-left: 2px; margin-top: 10px; overflow: hidden; position: relative;width: 500px;">
<?php
    $rsslist = array(
            "http://thehoopdoctors.com/online2/newfeed/",
            "http://thepigskindoctors.com/newfeed/",
            "http://thepuckdoctors.com/newfeed/",
            "http://thecagedoctors.com/newfeed/",
            "http://thedugoutdoctors.com/newfeed/",
            "http://videogoneviral.com/newfeed/"
        );
    foreach ( $rsslist as $rssurl ): /* For every URL in the feed list */
        $feed = fetch_feed($rrsurl);
        foreach( $feed->get_items() as $item ): /* For every item */ ?>
            <li class="news"><a style="color:white !important;" href="<?php echo $item->get_permalink();?>"><?php echo $item->get_title();?></a></li>
            <?php break; /* Do only once, we only need one item */ ?>
        <?php endforeach; ?>
    <?php endforeach; ?>
</ul>

Note how the code is fetching each URL separately instead of in multi-source mode and breaking out in the foreach $item loop as soon as an item is added. This should accomplish your task of getting one item from each feed in your ticker.

This code will do the same but grab each consecutive item from each feed:

<ul id="news-ticker" style="float: left;height: 15px !important; margin-left: 2px; margin-top: 10px; overflow: hidden; position: relative;width: 500px;">
<?php
    $rsslist = array(
            "http://thehoopdoctors.com/online2/newfeed/",
            "http://thepigskindoctors.com/newfeed/",
            "http://thepuckdoctors.com/newfeed/",
            "http://thecagedoctors.com/newfeed/",
            "http://thedugoutdoctors.com/newfeed/",
            "http://videogoneviral.com/newfeed/"
        );
    $feedlist = array();
    foreach ( $rsslist as $rssurl ) $feedlist []= fetch_feed( $rssurl ); /* store in feed array for later access */

    $current_item_cycle = 0;
    while ( sizeof($feedlist) ) { /* while feedlist is not empty */
        foreach ( $feedlist as $index => $feed ) { /* cycle through each feed */
            if (!$item = $feed->get_item($current_item_cycle++)) unset($feedlist[$index]); /* if feed has not more items unset */
            else /* echo it out */ { ?>
                <li class="news"><a style="color:white !important;" href="<?php echo $item->get_permalink();?>"><?php echo $item->get_title();?></a></li>
            <?php }
        }
    } ?>
</ul>
share|improve this answer
    
Thanks Man, I am very happy for his help, he always help me when i am worried about some thing. –  Mohammad Umer Jan 12 '12 at 15:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.