WordPress.org

Ready to get started?Download WordPress

Forums

Customizing the feed template (9 posts)

  1. kaihao96
    Member
    Posted 4 years 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 4 years ago #

  3. Shane G
    Member
    Posted 4 years 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 4 years 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 4 years 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 4 years 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?

  7. joneslee85
    Member
    Posted 4 years ago #

    @somwthingclassy: the code should go into functions.php of your theme

  8. magaworks
    Member
    Posted 4 years ago #

    Hi, I have wordpress 2.9.2
    I have implemented the code just like you say in my template function.php, and created my template "custom-feed.php" and uploaded both file in my theme folder. But I keep getting this error:

    Warning: require_once(/home/magawork/public_html/criaturas/wp-content/themes/Infinitycustom-feed.php) [function.require-once]: failed to open stream: No such file or directory in /home/magawork/public_html/criaturas/wp-includes/theme.php on line 996

    In lines 990 to 997 of this file "../wp-includes/theme.php" I have this code:
    function load_template($_template_file) {
    global $posts, $post, $wp_did_header, $wp_did_template_redirect, $wp_query, $wp_rewrite, $wpdb, $wp_version, $wp, $id, $comment, $user_ID;

    if ( is_array($wp_query->query_vars) )
    extract($wp_query->query_vars, EXTR_SKIP);

    require_once($_template_file);
    }

    Can anyone help me with this error? I am not a php programmer so I have no idea what this means.

  9. leadiv
    Member
    Posted 3 years ago #

    magaworks, I ran into this same issue. You need to add a '/' in front of your custom wordpress feed file. So this:
    load_template( TEMPLATEPATH . 'your-custom-feed.php');

    becomes:
    load_template( TEMPLATEPATH . '/your-custom-feed.php');

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags