令人困惑的是,get_the_category()
返回类别数组,因此需要循环遍历它们。
这听起来像是您想要分配给当前帖子的类别,也是类别id 11的子类别。如果是这样,请使用
<?php
// Get all the categories assigned to this post
$categories = get_the_category();
// Loop through the array that was returned
foreach($categories as $category) {
// If this category is a sub-category of category 11
if($category->parent == 11) {
// Set the $parent to it
$parent = $category;
// And exit the foreach loop
break;
}
}
?>