Not sure if this is the best approach - so happy to change - but I've set up a number of categories with child categories. Then on my landing page I list the parent categories - I'm using ACF to select the taxonomies I want -
<ul>
<?php foreach( $terms as $term ): ?>
<h2><?php echo $term->name; ?></h2>
<p><?php echo $term->description; ?></p>
<a href="<?php echo get_term_link( $term ); ?>">View all '<?php echo $term->name; ?>' posts</a>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Each link above takes me to categories.php where I list the child categories:
<?php
$term = get_queried_object();
$children = get_terms( $term->taxonomy, array(
'parent' => $term->term_id,
'hide_empty' => false
) );
if ( $children ) {
foreach( $children as $subcat )
{
echo '<li><a href="' . esc_url(get_term_link($subcat, $subcat->taxonomy)) . '">' . $subcat->name . '</a></li>';
}
}
?>
Problem is the link attached to the child categories stays on the category.php page and not the child category post.
How do I direct the child category link to the actual post?
Heres how I though it should flow:
- Landing page (containing list of parent categories)
- Category.php (containing child categories)
- Child post