I have a custom post-type "downloads", and within the downloads menu, I have download categories, the taxonomy name is "downloadcats".
My Downloads page uses a page template that lists all categories in the "downloadcats" taxonomy, this only shows parent categories. When a category is clicked, it uses the taxonomy archive template (taxonomy-downloadcats.php) and what I am trying to do is use conditional to say if there are child categories, display a list, otherwise show a list of posts.
In my taxonomy-downloadcats.php at the moment I have the following:
<?php
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false
) );
// print_r($children); // uncomment to examine for debugging
if($children) { // get_terms will return false if tax does not exist or term wasn't found.
echo 'show child categories';
} else {
if (have_posts()) :
while (have_posts()) : the_post(); ?>
<li><?php the_post_thumbnail('post-image'); ?>
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
<?php endwhile; ?>
<?php endif; ?>
<?php } ?>
The conditional statement is correct as if the category has no children it does show posts and if there are child categories, it displays "show child categories", I need to know what goes in there to make the parent's children appear.
Thanks
taxonomy.php
will display the current term plus all of it's child terms if there are any. Are you mixing built-in categories with custom taxonomy terms. Your termonology is really confusing, and what is more confusing even is that you are talking about a custom taxonomy but making use ofget_categories
. Please see this post and then file an edit with all the necessary info so that I can try and help you. This can be done with a filter only.