Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

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!

share|improve this question
1  
"does anyone kno how to make these link to their sub categories on a separate page?" -- I do not understand this. Please clarify. –  s_ha_dum Nov 2 '12 at 16:18
    
know* sure thing. I would like "Issue 7" the parent category to link to a separate page where its sub categories are listed out. –  dodgerogers Nov 2 '12 at 17:02
add comment

1 Answer 1

up vote 2 down vote accepted

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;
share|improve this answer
    
Hi Milo, thanks for the reply, this works great thank you, it follows through to the child categories nicely. How would you get the child category to link to all of its posts? Atm its renders with a strange url /category/iq-issue-4/news-iq-issue-4/ instead of /category/iq-issue-4/news –  dodgerogers Nov 5 '12 at 10:56
    
category pages automatically load the posts in that category, so you just need the standard loop to output them. as for category slugs, have you checked the categories to see what slugs are assigned, and does this actually differ? one issue you will run into is that you can't have multiple categories share the same slug, they must be unique. you won't be able to have simply news under each issue category. –  Milo Nov 5 '12 at 15:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.