Skip to content

Instantly share code, notes, and snippets.

@bainternet
Created January 1, 2013 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bainternet/4428853 to your computer and use it in GitHub Desktop.
Save bainternet/4428853 to your computer and use it in GitHub Desktop.
Custom categories feed plugin
<?php
/*
Plugin Name: custom-feed
Plugin URI: http://en.bainternet.info
Description: Custom categories feed
Version: 1.0
Author: bainternet
Author URI: http://en.bainternet.info
*/
function get_category_post($cat_id){
$post_args = array(
'numberposts' => 1,
'category' => $cat_id,
'fields' => 'ids'
);
$posts = get_posts($post_args);
return $posts[0];
}
function outputXMLFeed()
{
echo '<?xml version="1.0"?>';
echo '<items>';
$args=array(
'orderby' => 'name',
'order' => 'ASC'
);
$categories=get_categories($args);
foreach($categories as $category) {
echo '<item>';
echo '<catID>' . $category->term_id . '</catID>';
echo '<catname>' . $category->name . '</catname>';
echo '<postcount>' . $category->category_count . '</postcount>';
echo '<slug>' . $category->slug . '</slug>';
echo '<featured>' . get_the_post_thumbnail(get_category_post($category->term_id) , $size = 'post-thumbnail') . '</featured>';
echo '</item>';
}
echo '</items>';
}
add_action('init', 'add_my_feed');
function add_my_feed( ) {
add_feed("myFeed", "outputXMLFeed");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment