Advertisement
ridgey28

SimplePie WP-filter specific posts from multiple blogs

Jun 4th, 2013
227
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.11 KB | None | 0 0
  1. <?php  ///Start of SimplePie
  2.     //Add your feeds here
  3.     $rsslist = array( 'http://www.worldoweb.co.uk/feed',
  4.               'http://www.alfiemilne.org.uk/news/feed');
  5.        
  6.     $rss = fetch_feed($rsslist);
  7.  
  8.     if (!is_wp_error($rss)) :
  9.  
  10.         $maxitems = $rss -> get_item_quantity(10);//change item quantity if needed
  11.         $rss_items = $rss -> get_items(0, $maxitems);
  12.     endif;
  13. ?>
  14. /*The below function strips the first image from the feed. May or may not be useful*/
  15. <?php
  16.     function get_first_image_url($html) {
  17.         if (preg_match('/<img.+?src="(.+?)"/', $html, $matches)) {
  18.             return $matches[1];
  19.         }
  20. }?>
  21.    
  22. <ul class="rss-items" id="wow-feed">
  23. <?php
  24. if ($maxitems == 0){
  25.     echo '<li>No items.</li>';
  26. }
  27. else {
  28.     foreach ($rss_items as $item):
  29.         $id = $item->get_id(); //Get's IDs of posts
  30.  
  31.         //echo var_dump($id);//  Uncomment, save and reload browser to display ID's
  32.        
  33.         //Replace below with your ID's, can be from different blogs etc
  34.         $id_list = array('http://www.worldoweb.co.uk/?p=5787','http://www.worldoweb.co.uk/?p=5941','http://www.worldoweb.co.uk/?p=5807','http://www.alfiemilne.org.uk/news/?p=1225');
  35.        
  36.         if (array_keys($id_list,$id)) {?>
  37.            
  38.         <li class="item">
  39.             <span class="rss-image">
  40.               <?php echo '<img src="' . get_first_image_url($item->get_content()) . '"/>';?>
  41.             </span>
  42.             <span class="data">
  43.               <h5>
  44.                 <a href='<?php echo esc_url($item->get_permalink());?>'
  45.                 title='<?php echo esc_html($item->get_title());?>'>
  46.                     <?php echo esc_html($item->get_title());?></a>
  47.               </h5>
  48.             <span class="date-image">&nbsp;</span>
  49.                 <small><?php echo $item->get_date('F Y');?></small>
  50.                 <span class="comment-image">&nbsp;</span>
  51.                 <small><?php $comments = $item->                                   
  52.                         get_item_tags('http://purl.org/rss/1.0/modules/slash/', 'comments');?>
  53.                     <?php $number = $comments[0]['data'];?>
  54.                     <?php if ($number == '1') {
  55.                             echo $number . "&nbsp;" . "Comment";}
  56.                             else {
  57.                             echo $number . "&nbsp;" . "Comments";}?>
  58.                 </small>
  59.                 <p><?php echo $item->get_description();?></p>
  60.             </span>
  61.         </li>
  62.         <?php } //end if?>
  63.         <?php endforeach;?>
  64.         <?php } //end if;?>
  65. </ul>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement