How to display/list the post's sibling categories, but hide the current post cat
-
I have found the snnipet below and I want to do achieve two things:
1. Keep it from showing the current post category. In other words, show all the sibling categories except the category-name of the given post
2. I have used a comma as a separator, but how can I keep it from showing after the last item of the list?
Find the code below:
<?php global $post; $cats = get_the_category($post->ID); $catid = $cats[0]->cat_ID; while ($catid) { $cat = get_category($catid); $catid = $cat->category_parent; $catParent = $cat->cat_ID; } $categories = get_categories('child_of='.$catParent); foreach ($categories as $category) { echo '<a href="'.get_category_link($category->cat_ID).'">'.$category->cat_name.', </a>'; } ?>
Any thoughts would be greatly appreciated .. Thanks
Viewing 11 replies - 1 through 11 (of 11 total)
Viewing 11 replies - 1 through 11 (of 11 total)
- The topic ‘How to display/list the post's sibling categories, but hide the current post cat’ is closed to new replies.