Facebook Retrieve Recent Facebook Post(s) with Simple Pie RSS and PHP


/ Published in: PHP
Save to your folder(s)

Relies on "trunCate" a truncating function.


Copy this code and paste it in your HTML
  1. // Recent facebooks function
  2. function recentFacebooks($fbID, $number){
  3. include_once(ABSPATH.WPINC.'/rss.php');
  4.  
  5. $fbpost = fetch_feed("http://www.facebook.com/feeds/page.php?id=" . $fbID . "&format=rss20");
  6.  
  7. if (!is_wp_error( $fbpost ) ) :
  8. $maxitems = $fbpost->get_item_quantity($number);
  9. $rss_items = $fbpost->get_items(0, $maxitems);
  10. endif;
  11.  
  12. if ($maxitems == 0) echo '<p>No Recent Posts.</p>';
  13. else foreach ( $rss_items as $item ){
  14.  
  15. $content = html_entity_decode($item->get_content());
  16. $cutcontent = trunCate($content,160, " ");
  17.  
  18. echo '<p>' . $cutcontent . '</p>';
  19. }
  20. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.