In a plugin:
1. Create a function to produce your feed’s output. You can either load a template to produce it or just produce the output directly. Either way, you’ll have the full Loop capabilities and everything else, just like any other template.
2. Call add_feed($feedname, $function)
to add the feed type.
3. Then you can access the feed like any other.
Example:
function feed_fake($comment) {...do stuff...}
add_feed('fake', 'feed_fake');
Resulting URL:
http://example.com/blog/feed/fake/ or
http://example.com/blog/?feed=fake
…depending on your permalinks, of course.
Note that the function will receive one parameter. This will be true if the user is requesting a comment feed (a feed from the single post pages which contain all the reader comments). You can ignore it or not. Your call.
Thanks a lot for the quick answer, I’ll try that right now !
Didn’t know about the add_feed function.
I’m getting an error when trying that.
Here is my plugin code:
function feed_infosjeunes() {
// echo 'test';
}
add_feed('infosjeunes','feed_infosjeunes');
and here is the error i get:
Warning: in_array(): Wrong datatype for second argument in /Applications/MAMP/htdocs/styleandthecity/street-style-paris-fashion-week/wp-includes/rewrite.php on line 30
Warning: Cannot modify header information – headers already sent by (output started at /Applications/MAMP/htdocs/styleandthecity/street-style-paris-fashion-week/wp-includes/rewrite.php:30) in …
Ahh. I see the problem. It’s trying to alter the rewrite rules before the rewrite stuff has been loaded up.
Try waiting until the ‘init’ hook is called before calling the add_feed function.
function add_my_feed() {
add_feed(...);
}
add_action('init','add_my_feed');
Works like a charm ! Tanks again for the valuable help. You saved me a few hours and an headache.
I also needed to create custom feeds and this post came quite in handy.
I just added a plugin that might be relevant to those tackling the same problem, which might make custom feed creation a bit easier:
http://wordpress.org/extend/plugins/feed-wrangler/
Hey,
I tried the code in this post and the Feed Wrangler plugin, but didn’t seem to get what I needed.
If any of you have any insight into my problem, posted at http://wordpress.org/support/topic/169262 please let me know!
Cheers.
Thank you Otto – just the job!