2011-11-07 6 views
0

ここでは、シンプルなシンプルコードを使用しています。設定した他のフィードを初期化する方法はわかりません。基本的に私がしようとしているのは、それぞれの$ feedsを異なるdivに配置することです。最初のdivは3つのフィードすべてを表示し、その後はそれぞれdivを1つ表示します。複数のシンプルRSSフィードを表示しようとすると問題が発生しました。

<?php 
// Include the SimplePie library 
require_once('simplepie.inc'); 

// Because we're using multiple feeds, let's just set the headers here. 
header('Content-type:text/html; charset=utf-8'); 

// These are the feeds we want to use 
$feeds = array(
    'SITE ONE URL', 
    'SITE TWO URL', 
    'SITE THREE URL'); 

$feeds2 = array(
    'SITE ONE URL'); 

$feeds3 = array(
    'SITE TWO URL'); 

$feeds4 = array(
    'SITE THREE URL'); 


// This array will hold the items we'll be grabbing. 
$first_items = array(); 

// Let's go through the array, feed by feed, and store the items we want. 
foreach ($feeds as $url) 
{ 
    // Use the long syntax 
    $feed = new SimplePie(); 
    $feed->set_feed_url($url); 
    $feed->init(); 

    // How many items per feed should we try to grab? 
    $items_per_feed = 3; 

    // As long as we're not trying to grab more items than the feed has, go through them one by one and add them to the array. 
    for ($x = 0; $x < $feed->get_item_quantity($items_per_feed); $x++) 
    { 
     $first_items[] = $feed->get_item($x); 
    } 

    // We're done with this feed, so let's release some memory. 
    unset($feed); 
} 

// We need to sort the items by date with a user-defined sorting function. Since usort() won't accept "SimplePie::sort_items", we need to wrap it in a new function. 
function sort_items($a, $b) 
{ 
    return SimplePie::sort_items($a, $b); 
} 

// Now we can sort $first_items with our custom sorting function. 
usort($first_items, "sort_items"); 


// Begin the (X)HTML page. 
?> 
+0

また、私はちょうど私が配列を取り出し、ちょうど$ feed2-> set_feed_url(「SITE ONE URLを」)配置する必要があります実現します。 – conwaydev

答えて

0

私はあなたに何をしようとしているのかを理解する必要がありますが、助けてください。私の理解によれば、3つのフィードのすべてのコンテンツを上位のdivに取り込み、次に、それぞれのフィードのコンテンツを別々のdivにします。同様に:なぜ冗長性:それはあなたが望むものであるならば、私は私の2centsで投げるために

<div id='feeds'> 
feed1-content-1 
feed1-content-2 
feed1-content-3 
feed2-content-1 
feed2-content-2 
feed2-content-3 
feed3-content-1 
feed3-content-2 
feed3-content-3 
</div> 
<div id='feeds2'> 
feed1-content-1 
feed1-content-2 
feed1-content-3 
</div> 
<div id='feeds3'> 
feed2-content-1 
feed2-content-2 
feed2-content-3 
</div> 
<div id='feeds4'> 
feed3-content-1 
feed3-content-2 
feed3-content-3 
</div> 

希望ですか?しかし、コーダだけが本当に達成したいことを知っています。私の提案は簡単です:ちょうどdiv要素に段落を追加します。

$('#feeds').append('<p>'+feed+'</p>'); 
and the appropriate feed into the appropriate div in the same way. 
+0

彼らはすべてのニュースを言ったnavを望んでいるからだから - サイト1のニュース - サイト2のニュース - サイトの3つのニュース私はjqueryでdivを表示している。その愚かな私は知っている。 – conwaydev

関連する問題