Advertisement
ridgey28

rss-feed

Oct 9th, 2012
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.77 KB | None | 0 0
  1. <?php
  2. $rss = fetch_feed('http://www.worldoweb.co.uk/feed');//replace this with your url
  3. if (!is_wp_error( $rss ) ) :
  4.  
  5.     $maxitems = $rss->get_item_quantity(5);
  6.     $rss_items = $rss->get_items(0, $maxitems);
  7. endif;
  8. ?>
  9. <?php function get_first_image_url($html)
  10.         {
  11.             if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
  12.             return $matches[1];
  13.             }
  14.         }
  15. ?>
  16.  <?php
  17. function shorten($string, $length)
  18. {
  19.     $suffix = '&hellip;';
  20.     $short_desc = trim(str_replace(array("\r","\n", "\t"), ' ', strip_tags($string)));
  21.     $desc = trim(substr($short_desc, 0, $length));
  22.     $lastchar = substr($desc, -1, 1);
  23.         if ($lastchar == '.' || $lastchar == '!' || $lastchar == '?') $suffix='';
  24.                     $desc .= $suffix;
  25.         return $desc;
  26. }
  27. ?>
  28. <ul class="rss-items" id="wow-feed">
  29.     <?php
  30.         if ($maxitems == 0) echo '<li>No items.</li>';
  31.         else
  32.         foreach ( $rss_items as $item ) : ?>
  33.     <li class="item">
  34.         <span class="rss-image">
  35.             <?php echo '<img src="' .get_first_image_url($item->get_content()). '"/>'; ?>
  36.         </span>
  37.         <span class="data">
  38.         <h5><a href='<?php echo esc_url( $item->get_permalink() ); ?>' title='<?php echo esc_html( $item->get_title() ); ?>'> <?php echo esc_html( $item->get_title() ); ?></a></h5>
  39.             <span class="date-image">&nbsp;</span><small><?php echo $item->get_date('F Y'); ?> </small>
  40.             <span class="comment-image">&nbsp;</span><small><?php $comments = $item->get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');?><?php $number = $comments[0]['data']; ?>
  41.                 <?php if ($number == '1'){ echo $number."&nbsp;". "Comment"; } else {echo $number. "&nbsp;"."Comments";}?></small>
  42.             <p><?php echo shorten($item-> get_description(),'150');?></p>
  43.         </span>
  44.     </li>
  45.     <?php endforeach; ?>
  46. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement