WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Get Category Feed URL (14 posts)

  1. Connor Crosby
    Member
    Posted 2 years ago #

    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!

  2. Connor Crosby
    Member
    Posted 2 years ago #

    bump

  3. Connor Crosby
    Member
    Posted 2 years ago #

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

  4. hulku
    Member
    Posted 2 years ago #

  5. Connor Crosby
    Member
    Posted 2 years ago #

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

  6. esmi
    Forum Moderator
    Posted 2 years ago #

    get_query_var('cat')

  7. Connor Crosby
    Member
    Posted 2 years ago #

    @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! :)

  8. esmi
    Forum Moderator
    Posted 2 years ago #

    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>

  9. Connor Crosby
    Member
    Posted 2 years ago #

    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! :)

  10. esmi
    Forum Moderator
    Posted 2 years ago #

    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

  11. Connor Crosby
    Member
    Posted 2 years ago #

    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 :)

  12. esmi
    Forum Moderator
    Posted 2 years ago #

    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>
  13. Connor Crosby
    Member
    Posted 2 years ago #

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

  14. esmi
    Forum Moderator
    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Topic