Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Simplepie – Multiple SEPARATE feeds – HELP!!

  • This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #25567
    Wroathe
    Member

    How do you $feed->get_items as $item in separate divs for separate blogs? Like if I have two columns set up for two different blogs how do I specify which items to get from which blog? From what I’ve read it has something to do with get_feed but I’m extremely new to PHP so I’m faceplanting bigtime on getting this to work.

    #61286
    Wroathe
    Member

    Nevermind. I resolved the problem, didn’t realize I could treat the $feed variable as any other variable and just use two separate feeds $feed1 $feed2…

    :D Woot!

    #65583
    keithybhoy
    Member

    Hi

    I’m looking to achieve the same i.e. 2 separate feeds in different DIVs

    Here’s my code which isn’t working, can someone point me in the correct direction?

    <?php

    //get the simplepie library
    require_once(‘inc/simplepie.inc’);

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

    $feed->set_feed_url(array(
    http://www.theyworkforyou.com/search/rss/?s=margo+macdonald&#8217;,
    $feed2->set_feed_url(array(
    http://feeds.feedburner.com/CssTricks?format=xml&#8217;,
    ));

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

    //provide the caching folder
    $feed->set_cache_location(‘cache’);
    $feed2->set_cache_location(‘cache’);

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

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

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

    $start = 0;
    $length = 3;

    ?>

    And then the code for each DIV:

    <?php
    /*
    Here, we’ll loop through all of the items in the feed, and $item represents the current item in the loop.
    */
    foreach ($feed->get_items($start,$length) as $item):
    ?>

    <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
    <p><?php echo $item->get_description(); ?></p>
    <p><small>Posted on <?php echo $item->get_date(‘j F Y | g:i a’); ?></small></p>

    <?php endforeach; ?>

    <?php
    /*
    Here, we’ll loop through all of the items in the feed, and $item represents the current item in the loop.
    */
    foreach ($feed2->get_items($start,$length) as $item):
    ?>

    <h2><a href="<?php echo $item->get_permalink(); ?>"><?php echo $item->get_title(); ?></a></h2>
    <p><?php echo $item->get_description(); ?></p>
    <p><small>Posted on <?php echo $item->get_date(‘j F Y | g:i a’); ?></small></p>

    <?php endforeach; ?>

    #65593

    It would be helpful if you could say why something isn’t working – syntax error, output is not what was expected, or something.
    That said, the following looks odd:

    Code:
    //grab the feed
    $feed = new SimplePie();
    $feed2 = new SimplePie();

    $feed->set_feed_url(array(
    http://www.theyworkforyou.com/search/rss/?s=margo+macdonald&#8217;,
    $feed2->set_feed_url(array(
    http://feeds.feedburner.com/CssTricks?format=xml&#8217;,
    ));

    To initialise two feeds you simply need to:

    Code:
    #65599
    keithybhoy
    Member

    sorry, I should have included an error message – doh!

    saying that, your code example has fixed my issue – many thanks!

    #65600

    No problemo!

    Dave

Viewing 6 posts - 1 through 6 (of 6 total)
  • The forum ‘Back End’ is closed to new topics and replies.