当用户在子类别或单个帖子上时,此代码显示父类别的子类别列表。
即使没有生成列表,也会显示此列表周围的样式。采取行动look here where you\'ll see an empty black box - 我把它涂成黑色只是为了突出它。不相关,但此代码受another code in my functions.php.
当不存在子类别时,如何正确地将标记插入此代码并防止生成列表?
<?php
$categories = get_the_category();
echo \'<ul style="background:#000">\';
foreach($categories as $category){
$parent = $category->parent;
if($category->parent == 0){
}
else{
wp_list_categories("child_of=$parent&title_li");
}
echo \'\';
}
?>