WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. nicosFR
    Member
    Posted 6 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. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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.

  3. nicosFR
    Member
    Posted 6 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
    Member
    Posted 6 years ago #

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

  5. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    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');
  6. nicosFR
    Member
    Posted 6 years ago #

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

  7. ephramzerb
    Member
    Posted 6 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:
    http://wordpress.org/extend/plugins/feed-wrangler/

  8. kristarella
    Member
    Posted 6 years ago #

    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.

  9. kristarella
    Member
    Posted 6 years ago #

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

    Thanks!

  10. peterwsterling
    Member
    Posted 5 years ago #

    Thank you Otto - just the job!

Topic Closed

This topic has been closed to new replies.

About this Topic