Forums

Customizing the feed template (6 posts)

  1. kaihao96
    Member
    Posted 4 months ago #

    Hi,

    Can anyone out there help me how to customize the RSS feed template because my post format is very different. I don't use the normal box for content, I uses custom field instead. So I would like to include my custom field content in the RSS feed.

    Is that possible?

    Thanks

  2. Felix J
    Member
    Posted 3 months ago #

  3. Shane G
    Member
    Posted 3 months ago #

    Hi,

    Here is a piece of code to point to your own feed template and create an unique feed name.

    function create_my_customfeed() {
    load_template( TEMPLATEPATH . 'your-custom-feed.php'); // You'll create a your-custom-feed.php file in your theme's directory
    }
    add_action('do_feed_customfeed', 'create_my_customfeed', 10, 1);

    Now, you will need to modify your feed. You will now be able to access your feed at http://yoursite.com/?feed=customfeed. But what about how WordPress does the really neat rewriting of feeds from /?feed=rss to /feed/rss/? That requires using generate_rewrite_rules(), as described in the WP_Rewrite Codex page.

    http://codex.wordpress.org/Function_Reference/WP_Rewrite

    This piece of code will allow you to have any feed name, and dynamically “create” /customfeed.xml as well as a /feed/customfeed/ versions:

    function custom_feed_rewrite($wp_rewrite) {
    $feed_rules = array(
    'feed/(.+)' => 'index.php?feed=' . $wp_rewrite->preg_index(1),
    '(.+).xml' => 'index.php?feed='. $wp_rewrite->preg_index(1)
    );
    $wp_rewrite->rules = $feed_rules + $wp_rewrite->rules;
    }
    add_filter('generate_rewrite_rules', 'custom_feed_rewrite');

    In the first piece of code, we told the create_my_customfeed() function to look in your theme’s directory for a your-custom-feed.php file. This will be the feed template your feed will use.

    Thanks,

    Shane G.

  4. kaihao96
    Member
    Posted 3 months ago #

    I guess you didn't get want I meant.

    I wanted to include the custom field value into my CSSFEED, my content box is blank.

  5. kaihao96
    Member
    Posted 3 months ago #

    I guess you didn't get want I meant.

    I wanted to include the custom field value into my rss feed**, my content box is blank.

  6. somethingclassy
    Member
    Posted 2 months ago #

    Shane, thank you for the code, it seems to be exactly what I'm looking for (my goal is to output everything as XML for the purpose of importing it and using it in a Flash frontend).

    But I wasn't sure about where to put it.

    Where does the above code go?

Reply

You must log in to post.

About this Topic

Tags