Setting up category feed from single.php with category parents
-
I am trying to concatenate a category feed url string to put in single.php. I finally got it working but am getting some output that I can’t eliminate. Specifically, the post ID is being output on my page above the link. So I have two questions:
1. How do I get this code to stop outputting the post id above the link?
2. Is there a better way to do this? The code for doing the same thing on cateogry.php was a lot more simple (and is posted at the very bottom of this post), so I have a feeling I may be missing an implementation with a built in function or something.
Thanks for any thoughts.
Code I have put in single.php:
<?php $cat_from_post_id = get_the_category(the_ID()); //get child category from post id $slug = $cat_from_post_id[0]->slug; //get slug from array $cat_parent = $cat_from_post_id[0]->parent; //get parent category id from array $parent_cat_name = get_cat_name($cat_parent); //get parent category name from id $base_url = get_bloginfo( url ); //get base url ?> <a href='<?php echo $base_url . '/category/' . $parent_cat_name . '/' . '/feed';?>'>Subscribe to the category feed.</a>
For reference, this is how I implemented the category feeds from category.php and first tried, to no avail, to implement it on single.php.
<?php $this_category = get_category($cat); echo '<a href="'.get_category_feed_link($this_category->cat_ID, '').'">Subscribe</a>'; ?>
- The topic ‘Setting up category feed from single.php with category parents’ is closed to new replies.