我需要告诉我查看的当前自定义分类法归档页面是否有子类别。我有一个情况,有很多自定义类别与儿童,该网站只是显示在最后一行帖子。否则,它应该显示到下一步的类别的链接。我找到了这个片段,但它似乎不适用于自定义分类法。
function category_has_children() {
global $wpdb;
$term = get_queried_object();
$category_children_check = $wpdb->get_results(" SELECT * FROM wp_term_taxonomy WHERE parent = \'$term->term_id\' ");
if ($category_children_check) {
return true;
} else {
return false;
}
}
<?php
if (!category_has_children()) {
//use whatever loop or template part here to show the posts at the end of the line
get_template_part(\'loop\', \'index\');
}
else {
// show your category index page here
}
?>