• 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)
  • Thread Starter Connor Crosby

    (@ccmovies)

    bump

    Thread Starter Connor Crosby

    (@ccmovies)

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

    Thread Starter Connor Crosby

    (@ccmovies)

    @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?

    get_query_var('cat')

    Thread Starter Connor Crosby

    (@ccmovies)

    @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! ??

    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>

    Thread Starter Connor Crosby

    (@ccmovies)

    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! ??

    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>

    https://codex.www.ads-software.com/Function_Reference/get_category

    Thread Starter Connor Crosby

    (@ccmovies)

    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 ??

    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>
    Thread Starter Connor Crosby

    (@ccmovies)

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

    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.