Görünen Çoklu RSS PHP ile Feeds

1 Cevap php

Herkes bunu biliyor mu? Ben basit bir liste olarak tek bir beslemesini görüntülemek nasıl biliyorum, ama daha karmaşık alır. Ben bir listesini görüntülemek için istiyorum ama her kaynak list-style-image spesifik sahip, birden fazla kaynak var.

Örnek:

(img1) This is data from rss feed 1
(img2) This is data from rss feed 2

Çok yardım için teşekkürler!

Bu benim tek bir kaynak listesi için ne var.

# INSTANTIATE CURL.
$curl = curl_init();

# CURL SETTINGS.
curl_setopt($curl, CURLOPT_URL, "RSSURL");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);

# GRAB THE XML FILE.
$xmlTwitter = curl_exec($curl);

curl_close($curl);

# SET UP XML OBJECT.
$xmlObjTwitter = simplexml_load_string( $xmlTwitter );

$tempCounter = 0;

foreach ( $xmlObjTwitter->channel->item as $item )
{                    
    # DISPLAY ONLY 10 ITEMS.
    if ( $tempCounter < 11 )
    {
        echo "<li><a href=\"{$item -> guid}\">{$item -> title}</a></li>
";
    }

    $tempCounter += 1;
}

EDIT 1

Alright, Thanks a lot. Very helpful. I've attempted to implement it by: 1. Installing SimplePie into the root of my site in the PHP folder. 2. Implenting the given code. (No styling yet, want to get it functional first.)

Benim kod şu anda budur:

<?php
require_once('/simplepie.inc');

$feed = new SimplePie();
$feed->set_feed_url(array('rss1', 'rss2'));
$feed->init();
$feed->handle_content_type();
foreach ($feed->get_items(0, 100) as $item) {
    $n = array_search($item->get_feed(), $feeds);
    echo '<li class="feed'.$n.'">'.$item->get_title().'</li>';
}
?>\

Sitemde bu çıktıyı alıyorum:

set_feed_url(array('http://vimeo.com/user/likes/rss', 'http://vimeo.com/user/videos/rss')); $feed->init(); $feed->handle_content_type(); foreach ($feed->get_items(0, 100) as $item) { $n = array_search($item->get_feed(), $feeds); echo ' '.$item->get_title().' '; } ?>\

I'm obviously doing something wrong, but am having trouble discovering what it is. Thanks again.

1 Cevap

Birden fazla RSS beslemeleri toplayarak ve daha sonra bunları bir liste halinde görüntüleyerek: Bu iki sorun var gibi görünüyor.

1: SimplePie lib - RSS ile ilgili her şey için muhtemelen en basit ve en iyi biridir. Zaten bir çünkü dosya boyutu birisi için overkill, ama görünebilir. Ayrıca sizin için tarihe göre sıralama idare edecek. http://simplepie.org/

<?php
$feed = new SimplePie();
$feed->set_feed_url(array('http://rss1', 'http://rss2'));
$feed->init();
$feed->handle_content_type();
foreach($feed->get_items(0, 100) as $item) {
    $n = array_search($item->get_feed(), $feeds);
    echo '<li class="feed'.$n.'">'.$item->get_title().'</li>';
}
?>

2: Ne akamike dedi (ve silindi?), Ancak liste tarzı görüntüler bir ağrı olabilir - hizalamak için neredeyse imkansız. Daha esnek bir çözüm bunları kaldırmak ve arka plan kullanmak olacaktır.

CSS:

li.feed1, li.feed2 {
    list-style: none;
    background-position: left center;
    background-repeat: no-repeat; 
}

li.feed1 { background-image: url(feed1icon.png); }
li.feed2 { background-image: url(feed2icon.png); }