• Resolved Bubbajuju

    (@bubbajuju)


    <?php
    $cat_id = get_query_var('cat');
    $catlist = get_categories('child_of=' . $cat_id);
    if ($catlist) {
    wp_list_categories('echo=0&orderby=id&title_li=&child_of=' . $cat_id);
    } else {
    //Now instead of "No Categories" showing I want to re-display the child categories
    
    ?>

    Thanks for any help…

Viewing 4 replies - 1 through 4 (of 4 total)
  • Not sure I understand what you’re looking for here, but this would allow you to define what is displayed instead of “No Categories”:

    $cat_id  = get_query_var( 'cat' );
    $catlist = get_categories( 'child_of=' . $cat_id );
    $no_cats = 'This is what will show instead of No Categories';
    
    $args = array(
        'echo'             => 0,
        'orderby'          => 'id',
        'title_li'         => '',
        'child_of'         => $cat_id,
        'show_option_none' => $no_cats,
    );
    wp_list_categories( $args );

    Just make $no_cats a string that contains whatever message or markup you want to show.

    Thread Starter Bubbajuju

    (@bubbajuju)

    Thanks Shaun,
    (I really appreciate your time)
    Your code will actually answer what I originally wanted to do, which was just hide “No Categories” altogether or echo some other text.

    I was trying to incorporate show_option_none and couldn’t figure it out.

    I like the way you have written out the $arg = array(
    It’s not shortcode and it helps me to understand php better. (which I really want to learn…)

    Thanks again and I am marking this resolved!

    p.s. In my first post I was trying to just re-display the children of the parent category instead of printing “No Categories”.

    Thread Starter Bubbajuju

    (@bubbajuju)

    Here is the code (thanks Shaun) that worked for any future searchers.
    Instead of changing the “No Categories” I elected to put a “Previous Page” link. I wrapped it in a div class so I could style it.
    All I changed to Shaun’s code above is change the echo 0 to echo 1.

    <div class="categorychildren">
    <?php
    $cat_id  = get_query_var( 'cat' );
    $catlist = get_categories( 'child_of=' . $cat_id );
    $no_cats = '<A HREF="javascript:javascript:history.go(-1)">Previous Page</A>';
    
    $args = array(
        'echo'             => 1,
        'orderby'          => 'id',
        'title_li'         => '',
        'child_of'         => $cat_id,
        'show_option_none' => $no_cats,
    );
    wp_list_categories( $args );
    ?>
    </div>

    Awesome, glad I could help!

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Show Category Children But Hide "No Category" with Children List’ is closed to new replies.