[resolved] Creating a custom RSS feed (10 posts)

  1. nicosFR
    Posted 7 years ago #

    Hi !

    I need to have a rss feed for a partner that includes an image for each post.
    I started by developping a plugin that adds an enclosure to each item with the image.
    Unfortunately my partner doesn't get it. He gave me an example feed which contain HTML in the decription... what a shame.
    Unfortunately it's the only way to get the images to them.
    So I'm wondering how to do that...
    Create a new feed especially for that purpose seems like the best solution. But where should I add an action to build that feed ? Which action triggers the RSS feed generation ?

    Thanks for your help or for any ideas on how to work around the problem.

  2. 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.


    function feed_fake($comment) {...do stuff...}
    add_feed('fake', 'feed_fake');

    Resulting URL:
    http://example.com/blog/feed/fake/ or
    ...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.

  3. nicosFR
    Posted 7 years ago #

    Thanks a lot for the quick answer, I'll try that right now !
    Didn't know about the add_feed function.

  4. nicosFR
    Posted 7 years ago #

    I'm getting an error when trying that.

    Here is my plugin code:

    function feed_infosjeunes() {
    	// echo 'test';

    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 ...

  5. 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() {
  6. nicosFR
    Posted 7 years ago #

    Works like a charm ! Tanks again for the valuable help. You saved me a few hours and an headache.

  7. ephramzerb
    Posted 7 years ago #

    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:

  8. kristarella
    Posted 7 years ago #

    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!


  9. kristarella
    Posted 7 years ago #

    Found the answer here http://wordpress.org/support/topic/170995


  10. peterwsterling
    Posted 7 years ago #

    Thank you Otto - just the job!

Topic Closed

This topic has been closed to new replies.

About this Topic