WordPress.org

Ready to get started?Download WordPress

Forums

WP eCommerce
Issue with displaying product categories - Please help!! (1 post)

  1. Aboobacker P
    Member
    Posted 1 year ago #

    I Hope somebody will help me with this

    I want to display product categories on sidebar in the following way:

    1. All the parent categories (exclude some) will be displayed.
    http://popalgroup.com/zsneaker/products-page/

    2. if we click on a category (eg: Air Jordan) the child cats of that category will be displayed.
    http://popalgroup.com/zsneaker/products-page/air-jordan/

    3. Now the issue is, if I click on one of the sub category, the co- categories are displaying somewhere else (under Nike Dunk)!! (try clicking Air Jordan 1)
    http://popalgroup.com/zsneaker/products-page/air-jordan-1/

    Please help me to figure this out

    Code:

    <ul>
    <?php
    $queried_object = get_queried_object();
    $term_id = $queried_object->term_id;
    
    // Display the product categories
    $args = array(
        'orderby'                  => 'name',
        'order'                    => 'ASC',
        'hide_empty'               => 0,
        'hierarchical'             => 1,
        'exclude'                  => array(4,11,12,13),
        'taxonomy'                 => 'wpsc_product_category' );
    
     $brandCats = get_categories( $args );
    
        foreach ($brandCats as $brandCat) {
             $curID = $brandCat->cat_ID;
             settype($curID, "integer");
             $curLink = get_term_link($curID, 'wpsc_product_category');
                if(!$brandCat->category_parent) {
                    $curClass = $term_id ==  $curID ?  ' class="current-cat"' : '';
                    echo '<li'.$curClass.'><a href="'.$curLink.'">' . $brandCat->cat_name . '</a></li>';
                }
    
        // if there are child categories for the current category, display them
        if( $term_id ==  $curID ) {
            $args = array(
                'child_of'                 =>  $term_id,
                'orderby'                  => 'name',
                'hide_empty'               => 0,
                'order'                    => 'ASC',
                'orderby'                  => 'name',
                'taxonomy'                 => 'wpsc_product_category' );
             $brandCats = get_categories( $args );
             foreach ($brandCats as $brandCat) { }
                if ($brandCat->category_parent) {
                    $brandCats = get_categories( 'hide_empty=0&taxonomy=wpsc_product_category&parent='.$brandCat->category_parent );
                    sort($brandCats);
                    foreach ($brandCats as $brandCat) {
                        $curID = $brandCat->cat_ID;
                        settype($curID, "integer");
                        $curLink = get_term_link($curID, 'wpsc_product_category');
                        $curClass = $term_id ==  $curID ?  ' current-cat' : '';
                        echo '<li class="subcat '.$curClass.'"><a href="'.$curLink.'"> » ' . $brandCat->cat_name. '</a></li>';
                    }
                }
        }
    
        // product single page - current category highlite
        if(is_single()) {
            if ( get_my_terms() == $curID ) {
                $args = array(
                    'child_of'                 =>  $curID,
                    'orderby'                  => 'name',
                    'hide_empty'               => 0,
                    'order'                    => 'ASC',
                    'orderby'                  => 'name',
                    'taxonomy'                 => 'wpsc_product_category' );
                 $brandCats = get_categories( $args );
                 foreach ($brandCats as $brandCat) { }
                    if ($brandCat->category_parent) {
                        $brandCats = get_categories( 'hide_empty=0&taxonomy=wpsc_product_category&parent='.$brandCat->category_parent );
                        sort($brandCats);
                        foreach ($brandCats as $brandCat) {
                            $curID = $brandCat->cat_ID;
                            settype($curID, "integer");
                            $curLink = get_term_link($curID, 'wpsc_product_category');
                            $curClass = get_my_terms() ==  $curID ?  ' current-cat' : '';
                            echo '<li class="subcat '.$curClass.'"><a href="'.$curLink.'"> » ' . $brandCat->cat_name. '</a></li>';
                        }
                    }
            }
        }	
    
    }
    ?>
    </ul>

    http://wordpress.org/extend/plugins/wp-e-commerce/

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic