• Hello
    When a category is displayed in archive.php I have the subcategories listed using this working code

    <?php
    if ( is_category() ) {
      $current_cat = get_query_var('cat');
      wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat);
    }
    ?>

    How can this be changed to hide when there are no subcategories?

Viewing 1 replies (of 1 total)
  • either try to add the parameter for 'show_option_none', set to an empty string, to the code,

    wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat.'&show_option_none=');

    or try:

    <?php
    if ( is_category() ) {
      $current_cat = get_query_var('cat');
      $child_cats = wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat.'&echo=0&show_option_none=');
      if( $child_cats ) { echo $child_cats; }
    }
    ?>

    http://codex.ww.wp.xz.cn/Template_Tags/wp_list_categories

    the list would need to be wrapped in ul tags; do you have those in your code?
    if so, you will need to include them into the if statement.

Viewing 1 replies (of 1 total)

The topic ‘displaying subcategories within archive.php’ is closed to new replies.