需要从6个RSS(FETCH_FEED)获得正确的结果

时间:2012-01-11 作者:Mohammad Umer

我只需要从6个rss提要中获得一些正确的结果,我正在获取6个提要,并在http://thehoopdoctors.com/online2/newfeed/

我从6个rss提要中获得了结果,就像第一次从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/"

我只需要一个接一个。

我只需要从所有URL一个接一个地获取帖子"http://thepigskindoctors.com/newfeed/", 第一个岗位"http://thepuckdoctors.com/newfeed/", 第一次邮寄等等。

我的代码是

<?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>

1 个回复
最合适的回答,由SO网友:soulseekah 整理而成

您要寻找的可能是以下内容:

<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>
请注意,代码是如何分别获取每个URL的,而不是在多源模式下,并在foreach $item 添加项目后立即循环。这将完成您的任务,从您的股票行情中的每个提要中获取一个项目。

此代码将执行相同的操作,但从每个提要中获取每个连续项:

<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>

结束

相关推荐

FeedBurner在发布“Scheduled Post”时不更新

我到处找了找,找不到这方面的任何东西,所以我想看看你们是否能帮忙。我成功地安排了帖子并让他们发布-没有“错过时间表”的问题-但是当一篇预定的帖子发布时,WordPress不会ping Feedburner,我的提要也不会更新。我可以手动进入Feedburner并更新feed,但这很痛苦(好吧,这很容易,但我忘记了!这就是安排帖子的全部目的!:-)。是否有人知道Feedburner或WordPress中的设置需要更改才能使其正常工作?我的“隐私”设置设置为对搜索引擎可见。如果有任何帮助,请访问以下网站:ht