所以这是我正在尝试使用的主要simplepie代码,我真的不明白如何初始化我已经设置的其他提要。基本上我要做的就是将每个$ feed放入不同的div中,这样第一个div显示所有3个feed,然后在每个div之后显示一个div。
<?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 :(得分:0)
我想提供帮助,但需要更好地了解您的目标。根据我的理解,你想用三种饲料的所有内容填充顶部div,然后,在下面,每个饲料内容都有一个单独的div。像:
<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>
如果这就是你想要的,我想投入我的2cents:为什么冗余?然而,只有编码员才真正知道他想要达到的目标。我的建议很简单:只需在div中添加一个段落:
$('#feeds').append('<p>'+feed+'</p>');
and the appropriate feed into the appropriate div in the same way.