0

I have searched and found a lot of people asking about how to add a custom rss feed for custom post types/taxonomies. However that's not the problem right now.

I have 2 extra pages on my site that looks like the default index page (with loop and stuff), the only difference is that they have a different orderby. And I want a feed for those pages too. Putting /feed behind those pages returns a Comments feed with no items. How come? The code of those pages are almost identical to index.php and the feed link works fine there.

I understand there's a add_feed function. But I don't want a new feed type, just the default one is fine.

  • How have you created these "extra" pages? – s_ha_dum Jan 21 '14 at 13:56
  • I added two files to my theme folder, Recent-Page.php and QOTD-Page.php, then pasted the index.php code there, created two new pages with those new files as template. – Tony Fire Jan 21 '14 at 14:24
  • If I am not mistaken, there isn't going to be a feed for those pages, except for the comment feed. Think about it; all that the WordPress Core knows about is the query that gets the page. It does not know what your template code does. – s_ha_dum Jan 21 '14 at 14:31
  • Ah I see. I guess most people don't make extra pages with different queries. Oh well, guess I'll have to code a rss page from scratch. Thanks for clarifying. – Tony Fire Jan 21 '14 at 14:37
0

The only way to accomplish this would be to add in new rewrite rules for these urls. There are a bunch of different ways to accomplish this, but here's one example:

<?php 
add_filter( 'generate_rewrite_rules', 'me_filterRewriteRules' );

function me_filterRewriteRules( $wp_rewrite ) {
    $newRules = array();
    // Replace [your-slug] with the slug of your page
    $newRules['[your-slug]/feed/?$'] = 'index.php?feed=rss2';

    $wp_rewrite->rules = $newRules + $wp_rewrite->rules; 
}
?>

You'll need to add a new rule with the appropriate related query strings for each page you'd like to add a feed to.

  • Unfortunately I don't understand the code. I tried adding the code to function.php and replacing your-slug with qotd/recent. Couldn't get it to rewrite the feed. Anyway I did a workaround by writing a RSS feed page from scratch. – Tony Fire Jan 21 '14 at 16:42
  • 1
    You'd have to customize the code a bit more to get it to work. This was just an approach, not a final product. Glad you were able to figure it out. – MikeNGarrett Jan 21 '14 at 20:18
0

MikeNGarret's answer might work, I did not understand it though so I went with an alternative apporach. What I did was make a blank new page template instead, and coded it like a RSS/XML page with my new query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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