How to Use coreylib

Here are some examples to get you started.

Pull RSS feeds

Parsing an RSS feed for display is a pretty common task. RSS is just XML, so it's a natural application for coreylib. Here are some examples to get you started.

Link to the most recent story

The code:

<?php
  if ($rss = coreylib('http://www.squidoohq.com/lotd/feed/', '10 minutes')) {
    $item = $rss->get('item:first');
    if ($item->size()) {
      echo sprintf('<a href="%s" target="_blank">%s</a>', $item->get('link'), $item->get('title'));   
    }
  }
?>

The link:



    

Create a list of the last 5 stories

The code:

<ul>
  <?php
    if ($rss = coreylib('http://www.squidoohq.com/lotd/feed/', '10 minutes')) {
      $items = $rss->get('item', 5);
      foreach($items as $item) {
        echo sprintf('<li><a href="%s" target="_blank">%s</a></li>', $item->get('link'), $item->get('title'));
      }
    }
  ?>
</ul>

The list of links:

<ul>

Create a spotlight to feature one story

The code:

<?php 
  if ($rss = coreylib('http://www.squidoohq.com/lotd/feed/', '10 minutes')) {
    $item = $rss->get('item:first');
    if ($item->size()) {
      echo sprintf('<h4>%s</h4>', $item->get('title'));
      echo chopHTML($item->get('encoded'), 140, true);
      echo sprintf('<a href="%s" target="_blank">more...</a>', $item->get('link'));
    }
  }
?>

The spotlight: