0

Does anyone know how to do this? I know how to display a single feed as a simple list, but it gets more complicated. I want to display a list but have multiple sources, with each source having the list-style-image be specific.

Example:

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

Thanks so much for the help!

This is what I have for a single source list.

# 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.)

My code currently is this:

<?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>';
}
?>\

I'm getting this output on my site:

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.

3
  • 1
    Post a bit of code. I think this is more of a CSS than PHP problem. Commented May 9, 2010 at 22:21
  • can you add a style to your <li> element? Commented May 9, 2010 at 22:43
  • Sorry what do you mean? edit the code to show some style? Commented May 9, 2010 at 23:14

1 Answer 1

1

It seems that you have two problems: aggregating multiple RSS feeds and then displaying them in a list.

1: Use SimplePie lib -- probably the simplest and best one for anything related to RSS. Might seem as an overkill for someone because of the file size, but anyway. It will also handle sorting by date for you. 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: What akamike said (and deleted?), but list style images can be a pain -- almost impossible to align. A more flexible solution would be to remove them and use background.

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); }
Sign up to request clarification or add additional context in comments.

2 Comments

Any idea why I am getting that output on my site?
The require path ('/simplepie.inc') looks suspicious -- if you didn't modify the include_path, it probably looks into system root. Try using a relative path like '../simplepie.inc' or site's absolute path like '/home/user/www/site/simplepie.inc'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.