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: 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 "<?php single_cat_title(); ?>" 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 "<?php single_cat_title(); ?>" 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! 🙂
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 "<?php single_cat_title(); ?>" 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 🙂
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 "<?php single_cat_title(); ?>" via RSS">Subscribe</a>
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.