humbucker
Member
Posted 2 years ago #
Hello,
I would like to know if it's somehow possible to add an argument to the get_the_category function to only display categories (child of a parent category) a post belongs to.
E.g if my posts belongs to cat 1, 1>2, 3, 7
I d'like to write get_the_category(catId=1) so that it will ouput me the category name 1>2
Anything possibile ??
Thanks a lot!
Or this will only show child categories (use within the loop)
<?php
foreach((get_the_category()) as $category) {
if($category->parent != 0){
echo $category->cat_name . ' ';
}
}
?>
humbucker
Member
Posted 2 years ago #
If I use this solution, even the categories my post doesnt belong to will be shown ... no ?
No, it will only show child categories that are assigned to the post.
humbucker
Member
Posted 2 years ago #
This is what I've done :
<?php foreach((get_the_category()) as $chaine)
{ if($chaine->parent == 27){ echo $chaine->cat_name . ' '; }
}
?>
It works...slighty modified but working.
Thank you, you put me on the right tracks