• I am creating a store for tshirts I list on Amazon. I have a page that displays the children of category 15 with a custom template… some of those categories has children… right now, when you click on one of them it takes you to a page with a custom theme that displays all the tshirts (posts) in that category… my goal is, that when you click on a category that has childern categories, instead of getting the page with posts I want a page with the children categories… so you can drill down through the children..
    Something like this:

    Loop
    If Cat has children
    Link to page that lists children categories
    Else
    Link to page that displays posts in that category
    End else
    End loop

    Here is the code of the current page that shows the categories:

    ———-
    <?php /* Template Name: Show Cat Page */ ?>
    <?php
    get_header(); ?>
    <?php get_sidebar(‘top’);
    echo ‘<div id=”category-row”>’;
    $args = array(
    ‘parent’ => 15,
    ‘hide_empty’ => 0
    );

    foreach( get_categories( $args ) as $category) {
    if ( $category->term_id <> 15) { // hides ‘t-shirt category
    echo ‘<div class=”outer-category-container”>’;
    echo ‘<div class=”store-category-container”>’;
    echo ‘slug . ‘”>’;
    echo do_shortcode(sprintf(‘[wp_custom_image_category term_id=”%s”]’,$category->term_id));
    echo ‘<div class=”store-category-title”>’. $category->cat_name . ‘</div>
    ‘;
    echo ‘</span>’;
    echo ‘</div>’;
    echo ‘</div>’;

    $index++;
    if ($index % 5 == 0) {
    echo ‘</div><div id=”category-row”>’;
    }
    }
    }
    echo ‘</div>’;
    get_sidebar(‘bottom’); ?>
    <?php get_footer(); ?>
    ———-

    Any help would he appreciated.
    Steve

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    You can use the “parent” argument for a new WP_Term_Query object (or in get_terms() which is a wrapper for that class) to only get immediate children of any taxonomy term. If you supply 0 as the parent argument, you will get all top level terms of the taxonomy specified. When someone picks a term, use that term’s ID as the parent argument to get its immediate children. Should the term query not return any children, then run a product query to get products assigned the current term.

    Thread Starter SteveAx

    (@steveax)

    Thank you for your reply… while I’m sure it makes sense to someone with WP skill I am unfortunately not at that level.. I willl be researching and trying to learn based on your reply though. I understand the logic of what you are saying to do, just no idea how to code it… I iwll give it a shot and will be back if I run into trouble.
    Thanks again!
    Steeve

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Way to Drill down through child categories’ is closed to new replies.