treehouse : what would you like to learn today?
Web Design Web Development iOS Development

SimplePie problems

  • so I'm trying to use the simplepie that chris talked about in screencast #55 http://css-tricks.com/video-screencasts/55-adding-rss-content-with-simplepie/.

    I'm getting an error with the last line of code. If I remove the code, the error comes up on the next line of php (now the last line of php code)

    Any help would be appreciated.


    <?php
    //get the simplepie library
    require_once('http://website.com/wp-content/themes/mr-munoz/inc/simplepie.inc');

    //grab the feed
    $feedPolitico = new SimplePie();
    $feedPolitico->set_feed_url(array(
    'http://feeds2.feedburner.com/CssTricks',
    ));
    $feedPolitico->set_item_limit(3);

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

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

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

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

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

    //grab the feed
    $feedSmashing = new SimplePie();
    $feedSmashing->set_feed_url(array(
    'http://smashingmagazine.com',
    ));

    $feedSmashing->set_item_limit(3);

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

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

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

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

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

    //grab the feed
    $feedNPR = new SimplePie();
    $feedNPR->set_feed_url(array(
    'http://www.npr.org/rss/rss.php?id=1001',
    ));

    $feedNPR->set_item_limit(3);

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

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

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


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

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

    <div id=\"rss-container\">
    <div id=\"rss-title\"></div>
    <div id=\"politico\">
    <h3>Politico</h3>
    <?php if ($feedPolitico->error): ?>
    <p><?php echo $feedPolitico->error; ?></p>
    <?php endif; ?>
    <?php foreach ($feedPolitico->get_items() as $item): ?>
    <ul>
    <li><a href=\"<?php echo $item->get_permalink(); ?>\"><?php echo $item->get_title(); ?></a><br><p class=\"footnote\"><?php echo $item->get_date('j M Y | g:i a T'); ?></p></li>
    </ul>
    </div>

    <div id=\"smashing\">
    <h3>Smashing Magazine</h3>
    <?php if ($feedSmashing->error): ?>
    <p><?php echo $feedSmashing->error; ?></p>
    <?php endif; ?>
    <?php foreach ($feedSmashing->get_items() as $item): ?>
    <ul>
    <li><a href=\"<?php echo $item->get_permalink(); ?>\"><?php echo $item->get_title(); ?></a><br><p class=\"footnote\"><?php echo $item->get_date('j M Y | g:i a T'); ?></p></li>
    </ul>
    </div>

    <div id=\"npr\">
    <h3>NPR</h3>
    <?php if ($feedNPR->error): ?>
    <p><?php echo $feedNPR->error; ?></p>
    <?php endif; ?>
    <?php foreach ($feedNPR->get_items() as $item): ?>
    <ul>
    <li><a href=\"<?php echo $item->get_permalink(); ?>\"><?php echo $item->get_title(); ?></a><br><p class=\"footnote\"><?php echo $item->get_date('j M Y | g:i a T'); ?></p></li>
    </ul>
    </div>
    <div class=\"clear\"></div>
    </div><!-- end id=\"rss-container\" -->
  • Never used simplepie before, but the problem with the code you have posted is you aren't ending your foreach loops (stick endforeach; where you want each to end.) Obviously I don't know exactly what you are trying to achieve, but shouldn't the loops be inside the ul? So you have one list with lots of items rather than lots of lists with one item each?
  • As Tcooper says, I'm guessing you aren't closing something and are getting an 'Unexpected End' error on your file. Showing us the error message would help though...
  • Now I'm getting these errors:
    Warning: cache/5b60105eb4ce277db99d436af8b812b9.spc is not writeable in http://website.com/testmu/wp-content/th ... plepie.inc on line 1773

    Warning: cache/570cbd2a6f5e3c8d32b539d47fb9dc41.spc is not writeable in http://website.com/testmu/wp-content/th ... plepie.inc on line 1668

    Warning: cache/4f00777ba735f7a90601c8c02fadd110.spc is not writeable in http://website.com/testmu/wp-content/th ... plepie.inc on line 1773


    Is this a permission error?