• 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&#8217;

    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;' ));
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter Syamil MJ

    (@sy4mil)

    Any solution?

    Thread Starter Syamil MJ

    (@sy4mil)

    Just to share how I get around with this. This is by far the most efficient way that I get to show relevant topics from different forums I have on my website:

    // In in 'Category' show feeds from subforum related to it
    if (in_category('Politics')) {
    	include_once(ABSPATH . WPINC . '/rss.php');
    	wp_rss('https://link-to-politics-forum/rss', 5);
    }
    // Add more Categories you like
    elseif (in_category('Sci/Tech')) {
    	include_once(ABSPATH . WPINC . '/rss.php');
    	wp_rss('https://link-to-sci-tech-forum/rss', 5);
    }
    // If no related forum category, show global feed from forums i.e. 'latest-discussions'
    else {
    	include_once(ABSPATH . WPINC . '/rss.php');
    	wp_rss('https://link-to-latest-discusions-forum/rss', 5);
    }

    I’m using vBulletin for my site and this worked out quite well so far.

    Thread Starter Syamil MJ

    (@sy4mil)

    Just to add though, that wp_rss is deprecated according to WP, but I’m not sure for what reason. If someone knows a better alternative, let me know OK?

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Show different URL feed according to category’ is closed to new replies.