Advertisement
ulfben

WP: Customize WordPress' feeds

Oct 30th, 2011
307
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.97 KB | None | 0 0
  1. /*A simple way to supplement WordPress feeds. In this case, adding comment count and categories.
  2.  
  3. Just add this to your theme's function.php and you're off to the races.
  4. */
  5.  
  6. function ulfben_supplement_feeds($content){
  7.     $post_categories = wp_get_post_categories(get_the_ID());
  8.     $cat_list = array();
  9.     foreach($post_categories as $cat_id){
  10.         $cat_list[] = '<a href="'.get_category_link($cat_id).'" target="_top">'.get_cat_name($cat_id).'</a>';
  11.     }  
  12.     $comments = get_comments_number();
  13.     if($comments){
  14.         $comments .= ($comments == 1) ? ' comment' :  ' comments';
  15.     }else{
  16.         $comments = 'A penny for your thoughts!';
  17.     }
  18.     $comments = '<a href="'.get_comments_link().'" target="_top">'.$comments.'</a>';
  19.     return $content.
  20.         '<div style="display:block">
  21.             <small>Posted in: <em>'.implode(', ',$cat_list).'</em><br />'.
  22.                 $comments.
  23.             '</small>
  24.         </div>';
  25. }
  26. add_filter('the_excerpt_rss', 'ulfben_supplement_feeds');
  27. add_filter('the_content_feed', 'ulfben_supplement_feeds');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement