• Our blog is going to be feeding news to another site and we need to format it in XML (to the other site’s spec) and send it at regular intervals (or whenever there’s a new post).

    I’ve thought about creating a template for this, but wonder if it’s the right way to do it.

    I’ve searched for a plugin but couldn’t find one.

    The site uses the Feedburner plugin but also the <more> tag so the RSS only exports the first paragraph of every story (and the Feedburner XML format isn’t the right one anyway). In short, RSS is out.

    Does anyone have any thoughts?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator Samuel Wood (Otto)

    (@otto42)

    ww.wp.xz.cn Admin

    Create a new “feed”.

    A feed, in WordPress, is basically just a special template with the proper hook. This would do the trick:

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

    The resulting URL will be along these lines:
    http://example.com/blog/feed/fake/ or
    http://example.com/blog/?feed=fake
    …depending on your permalinks, of course.

    Now, the code in feed_fake would be basically similar to the stuff in feed_rss2.php or what have you. It’s just going to output XML, do the Loop, whatever you need to create your XML output. The existing feeds work exactly this way. In their feed functions, they simply do a load_template( ABSPATH . WPINC . '/feed-rss2.php' ); to create their output.

    Thread Starter jamesbc

    (@jamesbc)

    Thanks Otto.

    Let me see if I have this right (I’m relatively new to WP).

    I’d add that function to the function file, then create a new template called feed_fake.php (based on another feed template), tweak the formatting and I’d be good to go?

    What would I need to put in place of the “do stuff” line?

    Moderator Samuel Wood (Otto)

    (@otto42)

    ww.wp.xz.cn Admin

    Something along the lines of this would work for the “do stuff”:
    load_template( TEMPLATEPATH . '/feed-fake.php' );

    The idea is that when somebody asks for the feed, that function gets called. It can do anything you like to generate the feed. If you are putting the feed into a new file in the theme, than that line above will load and run it as any other template.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Create a regular XML post export’ is closed to new replies.