Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

At the risk of sounding completely ridiculous, i'm posting this question here as the nature of my query doesn't seem to help me much from google.

My wordpress default rss feeds makes use of post excerpt this feed is accessed via www.mydomain.com/feed

I have a requirement to make another RSS feed that is full text. How can create an additional RSS feed (that is private/given to only trusted parties).. preferably using a function but a plugin (as a last resort)?

share|improve this question
add comment

2 Answers

up vote 5 down vote accepted

Here is how to create a custom feed:

first create a new file in your theme's directory , name it your-custom-feed.php and put this code inside

<?php

     /**
      * custom RSS feed.
      *
      * @package WordPress
      */

     header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
     $more = 1;

    echo '<?xml version="1.0" encoding="'.get_option('blog_charset').'"?'.'>'; ?>

    <rss version="2.0"
        xmlns:content="http://purl.org/rss/1.0/modules/content/"
        xmlns:wfw="http://wellformedweb.org/CommentAPI/"
        xmlns:dc="http://purl.org/dc/elements/1.1/"
        xmlns:atom="http://www.w3.org/2005/Atom"
        xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
        xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
        <?php do_action('rss2_ns'); ?>
    >

        <channel>
            <title><?php bloginfo_rss('name'); wp_title_rss(); ?></title>
            <atom:link href="<?php self_link(); ?>" rel="self" type="application/rss+xml" />
            <link><?php bloginfo_rss('url') ?></link>
            <description><?php bloginfo_rss("description") ?></description>
            <lastBuildDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_lastpostmodified('GMT'), false); ?></lastBuildDate>
            <language><?php echo get_option('rss_language'); ?></language>
            <sy:updatePeriod><?php echo apply_filters( 'rss_update_period', 'hourly' ); ?></sy:updatePeriod>
            <sy:updateFrequency><?php echo apply_filters( 'rss_update_frequency', '1' ); ?></sy:updateFrequency>
            <?php do_action('rss2_head'); ?>
            <?php while( have_posts()) : the_post(); ?>
            <item>
                <title><?php the_title_rss() ?></title>
                <link><?php the_permalink_rss() ?></link>
                <comments><?php comments_link_feed(); ?></comments>
                <pubDate><?php echo mysql2date('D, d M Y H:i:s +0000', get_post_time('Y-m-d H:i:s', true), false); ?></pubDate>
                <dc:creator><?php the_author() ?></dc:creator>
                <?php the_category_rss('rss2') ?>

                <guid isPermaLink="false"><?php the_guid(); ?></guid>
                <description><![CDATA[<?php the_excerpt_rss() ?>]]></description>
            <?php if ( strlen( $post->post_content ) > 0 ) : ?>
                <content:encoded><![CDATA[<?php the_content_feed('rss2') ?>]]></content:encoded>
            <?php else : ?>
                <content:encoded><![CDATA[<?php the_excerpt_rss() ?>]]></content:encoded>
            <?php endif; ?>

                <wfw:commentRss><?php echo esc_url( get_post_comments_feed_link(null, 'rss2') ); ?></wfw:commentRss>
                <slash:comments><?php echo get_comments_number(); ?></slash:comments>
        <?php rss_enclosure(); ?>
            <?php do_action('rss2_item'); ?>
            </item>
            <?php endwhile; ?>
        </channel>
    </rss>

then add a simple function to call that template file using do_feed_$hook

//load feed template
function create_my_customfeed() {
    load_template( TEMPLATEPATH . 'your-custom-feed.php'); 
}
add_action('do_feed_mycustomfeed', 'create_my_customfeed', 10, 1);

Now when you access http://yoursite.com/?feed=mycustomfeed you will get a full text feed, no mater what you define inside WordPress admin.

Bonus

if you want to create a rewrite rule for your custom feed so your url could be:

http://yoursite.com/mycustomfeed.xml as well as a http://yoursite.com/feed/mycustomfeed/

add this code to your functions.php file:

//create feed rewirte rule

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;
}
share|improve this answer
    
Thanks for this brilliant tutorial. When i create the file (full-feed.php) and call it mysite.com/?feed=full-feed I get the following error ERROR: full-feed is not a valid feed template. –  Sledge81 Jul 14 '11 at 6:42
    
you need to change the hook, and file name in the code –  Bainternet Jul 14 '11 at 6:55
    
ahh my bad. Fixed. But I check the feed and it still gives out only a couple of lines from every post?? –  Sledge81 Jul 14 '11 at 7:21
add comment

Try something like this (not tested, simplified from more complex code):

add_feed('full', 'full_feed');

function full_feed() {

    add_filter('pre_option_rss_use_excerpt', '__return_zero');
    load_template( ABSPATH . WPINC . '/feed-rss2.php' );
}
share|improve this answer
    
Sure, I assume this code goes into functions.php but which file to call? There is already a /feed that goes default with the regular excerpt. So there needs to be another file or name that needs to be called?? –  Sledge81 Jul 14 '11 at 7:28
    
@Sledge81 the first argument of add_feed() is slug of feed being created. So this additional feed will be at /feed/full or ?feed=full (former depends if you have pretty permalinks enabled). –  Rarst Jul 14 '11 at 8:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.