Select name of category
-
How can i show the child of the main category in the single.php ? Thanks
-
single.php is going to show just one post, so `the_category(‘> ‘,’multiple’) will show the category parent/children.
But maybe this:
<?php
$category = get_the_category();
if ($category) {
wp_list_categories(‘child_of=’.$category[0]);
}
?>
`i’m not interested to show all the child categories, i’d show only the child of the current post 🙁
Actually now that I think about this I’m confused about what you are trying to achieve…
Regardless, here’s a correction:
wp_list_categories('child_of='.$category->cat_ID);i would show only the current post child categories.
for example i have this categories:
-> fruits [X]
–> apple [X]
–> strawberry
–> bananathe post is under “fruits –> apple”
i would show in single.php only the child category name “apple”
sorry but my english is not perfect so it’s a little difficult explain better for me 🙂
But you should be able to use ‘the_category’ for that.
When you write a post you should only be checking apple for the category.
ok, but what’s the difference if i select or not “fruits” ? it’s not better check “fruits” every time?
You should not check both the parent and the child. Just the child.
but why ?
Beacuse the child is automatically under the parent.
If you chose the parent as well, now it’s also part of that category, and it will display all the little “brothers and sisters” of the child…
is it possible show the rss link near the category with the_category ?
ok, thanks…the problem is now don’t work in_category(2) in single.php :((
ok, i’ve solved with this code
$in_subcategory = false; foreach( (array) get_term_children( 86, 'category' ) as $child_category ) { if(in_category($child_category))$in_subcategory = true; } if ($in_subcategory):but why if i use this code in header.php if i use
if ($in_subcategory):in single.php it doesn’t work ?someone ?
The topic ‘Select name of category’ is closed to new replies.