我有这样的层次结构:Category1-Subcategory1-Subcategory2-Post1Category2-Subcategory1
当我进入分类时,我需要显示子分类名称和描述///现在我使用以下代码:
<?php if (is_category()) {
$this_category = get_category($cat);
if (get_category_children($this_category->cat_ID) != "") {
echo \'<div id="catlist"><ul>\';
$childcategories = get_categories(array(
\'orderyby\' => \'name\',
\'hide_empty\' => false,
\'child_of\' => $this_category->cat_ID
));
foreach($childcategories as $category) {
echo \'<a href="\' . get_category_link( $category->term_id ) . \'" title="\' . sprintf( __( "View all posts in %s" ), $category->name ) . \'" \' . \'>\' . $category->name.\'</a>\';
echo \'<p>\'.$category->description.\'</p>\';
}
echo \'</ul></div>\';
}
}
?>
现在,我有子类别列表时,点击类别和空白页,如果我点击子类别链接,但我需要显示帖子时,我点击子类别列表。