Show different URL feed according to category
-
Hi guys.
Basically I wanted to include recent feeds from my forum posts. I have successfully done this using this code:
<?php include_once(ABSPATH.WPINC.'/rss.php'); wp_rss('https://my-forum/feed', 5); ?>
Now I wish I can further customize the feed url according to the category of any single post. For example, a post in the Politic category would use forum feeds from e.g ‘https://my-forum/politics/feed’
The php structure I have in mind is like this:
1. Check category slug of the post
2.
If category slug = politic, then $feed_url= http//my-forum/politics/feed
If category slug = fashion, then $feed_url= https://my-forum/fashion/feed
etc etc
Finally output wp_rss(‘$feed_url‘, 5);Any idea how this can be achieved?
Related: My solution currently is to use a custom post template for each category, where inside each template the feed url is different. But it’s overkill, I know! Here’s the code that I used
add_filter('single_template', create_function('$t', 'foreach( (array) get_the_category() as $cat ) { if ( file_exists(TEMPLATEPATH . "/single-{$cat->term_id}.php") ) return TEMPLATEPATH . "/single-{$cat->term_id}.php"; } return $t;' ));
- The topic ‘Show different URL feed according to category’ is closed to new replies.