Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I'm currently developing a theme for a client that need a "catalog" in a page, I made that catalog with a custom taxonomy and some AJAX, until that everything is fine but the products of that catalog are ordered under categories and sub-categories so when a client click on the main category it must show the sub categories in another menu and list all the products on the first sub-category not all the products on each subcategory (like is currently done).

I generated the menus with this code:

<?php
$term = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
$parent = get_term($term->parent, get_query_var('taxonomy') );
$grandparent = get_term($parent->parent, get_query_var('taxonomy') );
$children = get_term_children($term->term_id, get_query_var('taxonomy'));
if (!is_single()) {

if (!$parent->term_id && sizeof($children) > 0) {
    echo 'categoria';
    $args = array(
        'child_of' => $term->term_id,
        'taxonomy' => $term->taxonomy,
        'hide_empty' => 1,
        'hierarchical' => true,
        'depth'  => 1,
        'title_li' => ''
        );?>

        <ul> <?php  wp_list_categories( $args ); ?></ul>
        <?php
    } else {
        if ($parent->term_id && sizeof($children) > 0) 
        {           
            $args = array(
                'child_of' => $parent->term_id,
                'taxonomy' => $term->taxonomy,
                'hide_empty' => 1,
                'hierarchical' => true,
                'depth'  => 1,
                'title_li' => ''
                );?>

                <ul> <?php  wp_list_categories( $args ); ?></ul>
                <?php

            } else {
                $args = array(
                    'child_of' => $grandparent->term_id,
                    'taxonomy' => $term->taxonomy,
                    'hide_empty' => 1,
                    'hierarchical' => true,
                    'depth'  => 1,
                    'title_li' => ''
                    );?>

                    <ul> <?php  wp_list_categories( $args ); ?></ul>
                    <?php
                }
            }
        } 
?>

and it shows me the menu for the categories and another code similar for showing the sub-categories in other menu.

The categories are in a hierarchy like this:

Is there someone that can point me out how to do it? Sorry if my English isn't good enough to explain my problem, I'm not a native English speaker.

share|improve this question
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.