• Let’s say I have 3 main categories which can be displayed as:

    <?php wp_list_cats(‘children=0’); ?>

    When this category is clicked it shows all children of that category:

    <?php wp_list_cats(‘&child_of=’.$_GET[‘cat’]); ?>

    So far so good,

    The problem is if there are multiple children of the parent, it drops the other children when one of the child links is clicked.

    How would I modify the code to look for all children. Basically look back up the chain to the parent and use that catID to display all child links for the parent always.

    Thanks for any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter bedient

    (@bedient)

    I need a function like get_category_parents() but one that returns just the first cat_ID then I could pass that to wp_list_cats()

    Does that make since?

    Thread Starter bedient

    (@bedient)

    Okay, playing hard to get eh? This is where I’m at but since I’m a php newbie I not sure how to loop.

    <?php
    $currentID = $cat;
    $query = $wpdb->get_row(“SELECT category_parent FROM $wpdb->categories WHERE cat_ID = $currentID”); ?>
    <?php wp_list_cats(‘recurse=0&child_of=’.$query->category_parent); ?>

    The problem is this only get the previous parent not the root. I need to loop until I hit the category_parent = 0

    HELP?

    <?php wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=16’); ?>

    have you tried this.

    child_of=16 ? change the # to parent cat ID

    I made a single-16.php that Post Templates by Category plugin finds and views that one category different from all others. Whys is this important. Because, I think your try to do what I am doing. I used the single-16.php file to call that function like a sub menu after <?php get_header(); ?>

    <div id=’subpagemenu’>

      <h2>
      <?php wp_list_cats(‘sort_column=id&optioncount=0&use_desc_for_title=0&child_of=16’); ?>
      </h2>

    </div>

    I hope thats what you wanted to do.

    Thread Starter bedient

    (@bedient)

    I’ll take a look. Thanks for the response. I have a tweak going that does what I think I want but I haven’t tested it much.

    <?php wp_list_cats(‘children=0’); ?>

    <?php
    $currentID = $cat;
    $query = $wpdb->get_row(“SELECT cat_ID, category_parent FROM $wpdb->categories WHERE cat_ID = $currentID”);
    if ($query->category_parent != 0) {

    $thiscatID = $query->category_parent;

    while ( $thiscatID != 0 ) {
    $query = $wpdb->get_row(“SELECT category_parent FROM $wpdb->categories WHERE cat_ID = $thiscatID”);
    if ( $query->category_parent != 0 ) {
    $thiscatID = $query->category_parent;
    } else {
    break;
    }
    }

    wp_list_cats(‘recurse=0&child_of=’.$thiscatID);
    } else {
    wp_list_cats(‘recurse=0&child_of=’.$query->cat_ID);
    }

    ?>

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘wp_list_cats() show all childs of parent regardless’ is closed to new replies.