Support » Fixing WordPress » Get Category Feed URL

  • Resolved Connor Crosby

    (@ccmovies)


    Hello,

    I am making a WordPress theme that allows a user to subscribe to the RSS feed of the category they’re viewing.

    For example, if they’re on the “Tutorials” category (example.com/category/tutorials/) then there is a “Subscribe via RSS” link.

    I have been searching and testing for a couple hours and cannot seem to get it to work. Anyone know a solution? Thank you!

Viewing 13 replies - 1 through 13 (of 13 total)
  • bump

    Or maybe if there is a way to get the slug of the current category?

    @hulku: I’d prefer not to use a plugin. Anyone know of a PHP code I can use to grab the slug of the current category?

    esmi

    (@esmi)

    Forum Moderator

    get_query_var('cat')

    @esmi: That did work… sorta. Here is the code I used:

    <a id="heading-rss-link" href="<?php get_query_var('cat') ?>/feed/" title="Subscribe to only posts from &quot;<?php single_cat_title(); ?>&quot; via RSS">Subscribe</a>

    When I used that, for some reason that links to example.com/feed/. When I remove the “/feed/” it then links to the current category url. Is there any way I can fix that? Thank you! 🙂

    esmi

    (@esmi)

    Forum Moderator

    Try:

    <a id="heading-rss-link" href="<?php echo get_query_var('cat') ?>/feed/" title="Subscribe to only posts from &quot;<?php single_cat_title(); ?>&quot; via RSS">Subscribe</a>

    So close! For some reason it displays both the slug and ID. Anyway to display just the slug? I’d really like to implement this feature into my blog. I appreciate the help! 🙂

    esmi

    (@esmi)

    Forum Moderator

    Sorry – my bad. Try:

    <?php $this_cat = get_category(get_query_var('cat'),false);?>
    <a id="heading-rss-link" href="<?php echo $this_cat->slug; ?>/feed/" title="Subscribe to only posts from &quot;<?php single_cat_title(); ?>&quot; via RSS">Subscribe</a>

    http://codex.wordpress.org/Function_Reference/get_category

    That works, except it’s the wrong URL. Instead of just being example.com/category/name/feed/, it’s example.com/category/name/name/feed/ – meaning the category slug appears twice. Any way to fix that? Again, I appreciate your help 🙂

    esmi

    (@esmi)

    Forum Moderator

    Forgot the “static” bits of the feed url. Try:

    <?php $this_cat = get_category(get_query_var('cat'),false);?>
    <a id="heading-rss-link" href="<?php echo home_url( '/' ) . 'category/' .$this_cat->slug; ?>/feed/" title="Subscribe to only posts from &quot;<?php single_cat_title(); ?>&quot; via RSS">Subscribe</a>

    Sweet!! Thank you very much for your help esmi, I truly appreciate it 😀

    esmi

    (@esmi)

    Forum Moderator

    No problem. Sorry it took a couple of attempts to get it right.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘Get Category Feed URL’ is closed to new replies.