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 } ?>
WordPress Check if Category Has Children
This bit of code allows you to check to see if the current category archive page has child categories. I needed to check this on a site where until you were viewing a category that has no children, you saw category listing pages and then when the category has no children, you see the listing of posts for that category at the end of the line.