Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6207223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T05:35:34+00:00 2026-05-24T05:35:34+00:00

I’m using SimplePie to combine various RSS feeds, and I want to control the

  • 0

I’m using SimplePie to combine various RSS feeds, and I want to control the output of each individual feed item based on the source for that item. My ultimate goal is to be able to control the content and style of an item based on where its coming from.

I’m using the code below to sort feed items based on their the source link. Then, based on the source, I want to include the appropriate snippet of PHP to dictate which content to pull.

<?php foreach ($feed->get_items($start,$length) as $item):

    if ($item->get_feed()->get_link()=="http://example.com/FeedURL1"):
            include 'includes/FeedSource1.html';

    elseif ($item->get_feed()->get_link()=="http://example.com/FeedURL2"):
            include 'includes/FeedSource2.html';

    elseif ($item->get_feed()->get_link()=="http://example.com/FeedURL3"):
            include 'includes/FeedSource3.html';

    else:
            echo '<li>fail</li>';
    endif;

endforeach; ?>

Here’s the problem I’m encountering: the first “if” statement works fine if an item is TRUE, but if it is FALSE, then it defaults to the final “else” statement, apparently bypassing the “elseif” statements that are in between.

I’ve tested different items in the first “if” statement, so I know that my source detection code is working, but anything that is placed after an “elseif” is automatically ignored.

I’ve looked everywhere to figure out what’s wrong here, and from what I can tell I’m using the correct formatting for if/else statements. It’s likely I’m making a silly parse error or something, as I’m fairly new to PHP. But any help/advice would be much appreciated!

Example snippet that I would include for an item based on the feed source:

<li>
<a href="<?php echo $item->get_permalink(); ?>">
<?php echo substr($item->get_title(), 0, 250) . ''; ?>
<br><span> <?php echo $item->get_date('m.d.y / g:ia'); ?></span></a>
</li>

For reference, here is the SimplePie code I’m using at the top of the page:

<?php

//get the simplepie library
require_once('simplepie.inc');

//grab the feed
$feed = new SimplePie();

$feed->set_feed_url(array(
    'http://example.com/FeedSource1.rss',
    'http://example.com/FeedSource2.rss',
    'http://example.com/FeedSource3.rss',
));

//enable caching
$feed->enable_cache(true);

//provide the caching folder
$feed->set_cache_location('cache');

//set the amount of seconds you want to cache the feed
$feed->set_cache_duration(600);

//init the process
$feed->init();

//control how many feed items are shown
$start = 0;
$length = 25;

//let simplepie handle the content type (atom, RSS...)
$feed->handle_content_type();

?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T05:35:35+00:00Added an answer on May 24, 2026 at 5:35 am

    Try something like:

    <?php foreach ($feed->get_items($start,$length) as $item):
        $link = $item->get_feed()->get_link();
        switch ($link) {
            case 'http://example.com/FeedURL1':
                include 'includes/FeedSource1.html';
                break;
            case 'http://example.com/FeedURL2':
                include 'includes/FeedSource2.html';
                break;
            case 'http://example.com/FeedURL3':
                include 'includes/FeedSource3.html';
                break;
            default:
                echo 'fail';
                break;
        }
    endforeach; ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
this is what i have right now Drawing an RSS feed into the php,
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.