Viewing 11 replies - 1 through 11 (of 11 total)
  • http://codex.wordpress.org/Template_Tags/wp_list_categories

    Search for hide_empty. Does that get you what you want?

    Thread Starter robmaguire

    (@robmaguire)

    Unfortunately not, as categories without posts are already hidden.

    There is a header on each category page that lists the children of that category. If there are no children, I would like this header to be hidden. This is the challenge at hand!

    I guess what I am looking for might be PHP code that says IF children exist, show this header and list children. Otherwise, do nothing!

    Here is the current code:

    <?php if ((is_category())||(is_single())) { ?>

    • <h2>Categories</h2>
      <?php if($parent_category->cat_name == ”) { ?>
      <?php wp_list_cats(‘child_of=’.$this_category->cat_ID); ?>

    <?php } else { ?>

      <?php wp_list_cats(‘child_of=’.$parent_category->cat_ID); ?>

    <?php } ?>

    There is a header on each category page
    It would help if you don’t state untrue things.

    You are talking about your LEFT SIDEBAR, not the webpage.
    Precise description of the problem is always helpful.

    Move that h2 Catgeories /h2 inside the if statement to appear only when you have children cats.

    Thread Starter robmaguire

    (@robmaguire)

    Sorry… I’ve taken over tech duty for this blog, and WP is rather new to me. Thanks for the suggestion. Nonetheless, it is the if statement in particular I’m having difficulty with. Other than the main doc on conditional tags, where could I go for advice / reading on how to deal with this particular situation?

    You could try this (which is exactly what moshu suggested you do):

    <?php if ((is_category())||(is_single())) { ?>
    
    <?php if($parent_category->cat_name == '') { ?>
    <h2>Categories</h2>
          <?php wp_list_cats('child_of='.$this_category->cat_ID); ?> 
    
    <?php } else { ?>
    
          <?php wp_list_cats('child_of='.$parent_category->cat_ID); ?> 
    
    <?php } ?>

    Thread Starter robmaguire

    (@robmaguire)

    I tried moshu’s suggestion, and the only change was that the horizontal bars above and below the “no categories” text disappeared.

    <?php if($parent_category->cat_name == '') { ?>

    Does this not just mean “If category name = anything”? If so, won’t the rest of the code always try to display some sort of category children?

    So you mean that is still displayed “No categories” in your sidebar and it still displayed the word “Categories”?

    Try this:

    <?php if ((is_category())||(is_single())) { ?>
    
    <?php if($parent_category->cat_name == '') { ?>
    <h2>Categories</h2>
          <?php wp_list_cats('child_of='.$this_category->cat_ID); ?> 
    
    <?php } else { ?>
    
    <p>TEST</p> 
    
    <?php } ?>

    Does the word TEST show up on your page?

    Thread Starter robmaguire

    (@robmaguire)

    Hi tsguitar, that is precisely what I mean. The “Categories” header and “No categories” text below it just won’t go away!

    I tried your code and the output stayed the same–the word TEST did not show up.

    But does it show up on your other pages in other categories?

    Thread Starter robmaguire

    (@robmaguire)

    The TEST shows up in the sidebar of pages for the children of main categories (when children exist, of course), but it still shows “No Category” in the sidebar of category pages without children.

    i’m having the same problem.
    All i want is to display a menu that shows ONLY the children categories WHEN they exist in that parent category.
    They already shows, with the code bellow:

    <?php echo wp_list_categories('title_li=&exclude=1&use_desc_for_title=0&child_of='.$cat);?>

    but in when a category dont have children, it reads: “No Category” all the time!

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Categories: Stop Children from Displaying When No Children Exist’ is closed to new replies.