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.

I want to add a custom feed on my site for SEO purposes.

So, I first copy the /wp-includes/feed-rss2.php file into my theme folder and renamed it. I figured I'll be able to easily edit my feed.

Then I add this code :

function yandex_news_feed() {
load_template(TEMPLATEPATH . '/yandex-news.php'); 
}

function yandexnews_add_feed() {
add_feed('do_feed_yandexnews', 'yandex_news_feed');
}

add_action('init', 'yandexnews_add_feed');

I tried with many many ways and read a lot of documentation (almost always the same, a lot of people add rewrite_rules to the code but that's not the issue here) and source for add_feed tell that rewrite rules are taken care of.

But, anyway, that's not working at all, weither i'm doing http://infoglam.exigences.biz/?feed=yandexnews or http://infoglam.exigences.biz/feed/yandexnews ; that's the same : blank page, empty, nothing.

Please note that if use volontarily incorrect name like http://infoglam.exigences.biz/?feed=yandexnews5 I get a error ERROR: yandexnews5 is not a valid feed template. so it looks loke the feed name is registered, but the template isn't executed.

I have check permissions on template file, i tried with and without do_feed_ ; I tried with include instead of load_template()

I guess I could at the end use a template page with a blank page on the admin, but I find this not elegant - if efficient and quick. I will use several feeds on the site and I don't really want to deal with blank pages, and if I use the theme elsewhere I will need to create pages again, it will be best to have it concelead with the theme.

I guess the problem could be with the loading of the template but now I'm completely lost and cannot find where i'm doing it wrong.

Could someone give me a hand please ?

share|improve this question
    
Maybe I need to make some query first ? ... –  Simon Mar 22 '12 at 14:38
    
Now something very weird : to check I have added this code which worked as a test. After I remove the code from functions.php ... the special feed still working (for 20 mins so it's not a caching issue). I'm getting mad. –  Simon Mar 22 '12 at 15:21
    
add_feed Does not take care of fetching posts for you. You'll need to do that on your own. Also, you need to flush your rewrite rules to make it work. –  chrisguitarguy Mar 22 '12 at 22:54
    
No I finally get it : add_feed is like adding a new filter name for displaying content, based on url (the normal query), that will use the designated template. Right now, I don't flush the rewrite rule because I don't care using the ?feed= syntax (which I find more clear to separate from user content). Tx. –  Simon Mar 22 '12 at 23:00
add comment

1 Answer

Code is working :

add_feed('myfeed_rss2', 'my_feed');

function my_feed() {
add_filter('pre_option_rss_use_excerpt', '__return_zero');
load_template( TEMPLATEPATH . '/custom-feed.php' );
}

RSS is contextual : if I add ?feed=myfeed_rss2 after index url, this will tell WP to display the content of the home with the template custom-feed.php - it's more a filter than anything else. I was considering RSS from a wrong point of view.

If I add ?feed=myfeed_rss2after a category page url, it will display the category page with the template custom-feed.php.

I didn't find a way still to alter the query from the template, this should be done differently, i.e. creating a special page in theme and then calling the RSS template upon it (for example, having a RSS feed 50 article long).

The RSS template is only the strict XML structuration of the content, with the ability to use PHP code to add information (like file length in bytes for enclosures).

ADDITIONALLY

Something reaaally important if people try to use / manage custom feed : feed only are created / modified upon post modification / addition. To put it straight, you have to publish a new post (or put some old one as draft, do some test, then re-publish it, do some test...) to check any change made into the RSS template.

share|improve this answer
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.