Parent Category link to its sub categories on different page

I am creating a magazine style wordpress site. We have multiple issues which will be parent categories and these will have around 3-5 sub categories. Every quarter we will create a new issue with new subcategories.

E.g.

Read More

Issue 7 ->
news
journal
worldview
letters
etc…

I have a page which lists all of the parent categories and their associated magazine style cover images but I need these to link to a page which lists out that parent categories’ sub categories.

my code for the magazine parent categories is below if

<?php foreach (get_categories('exclude=9') as $cat) : ?>
  <?php if ($cat->parent > 0) continue; ?>
   <div id="magazine">
     <a href="<?php echo get_category_link($cat->term_id); ?>" id="link"><?php echo $cat->cat_name; ?></a>
     <img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
   </div>
  <?php endforeach; ?>
</div>
<?php endwhile; // end of the loop. ?>  

does anyone know how to make the parent category link to a page where their sub categories are listed? any help would be massively appreciated!

Related posts

Leave a Reply

1 comment

  1. I think the simplest way would be to just use the category archives that WordPress already generates. Change the category base in permalink settings to issues so you have nice URLs, then in the category template, check if you’re viewing a top level or child category, and display the appropriate markup:

    $this_category = get_queried_object();
    
    // if parent is 0, category is top level
    if( 0 == $this_category->parent ) :
    
        // top level category,
        // show child categories of this issue
        $args = array(
            'child_of' => $this_category->term_id,
            'title_li' => '',
            'hide_empty' => 0
        );
    
        // output a list of child cats for this issue
        // see also get_categories or get_terms if you wish to use your own markup
        wp_list_categories( $args );
    
    else :
    
        // child category,
        // show articles in this subcategory, etc.
        echo 'child category';
    
    endif;