Home Forums Basel support forum sort categegories in .basel-product-categories

sort categegories in .basel-product-categories

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #150244

    D0R1AN
    Participant

    Hello,

    how do I sort the categories in .basel-product-categories (e.g. https://demo.xtemos.com/basel/product-category/watches/)?

    It seems to be alphabetical in my shop instead of the order I set in the backend.
    Please advise.

    Thanks,
    Dorian

    #150290

    Hello,

    Unfortunately, there is no option to sort the categories in the shop page heading.

    Best Regards

    #150389

    D0R1AN
    Participant

    Hello,

    no big deal if it’s not sortable via theme settings. Surely it must be sortable somehow, though.
    Would you mind asking your programmer how to set the ‘orderby’ => ‘menu_order’ there?

    Thank you.
    Dorian

    #150486

    Hello,

    Please insert this code into functions.php of the child theme:

    function basel_product_categories_nav() {
        global $wp_query, $post;
        $show_subcategories = basel_get_opt( 'shop_categories_ancestors' );
        $show_categories_neighbors = basel_get_opt( 'show_categories_neighbors' );
        $list_args = array(  
            'taxonomy' => 'product_cat', 
            'hide_empty' => false 
        );
        // Menu Order
        $list_args['orderby'] = 'menu_order';
        // Setup Current Category
        $current_cat   = false;
        $cat_ancestors = array();
        if ( is_tax( 'product_cat' ) ) {
            $current_cat   = $wp_query->queried_object;
            $cat_ancestors = get_ancestors( $current_cat->term_id, 'product_cat' );
        }
        $list_args['depth']              = 5;
        $list_args['child_of']           = 0;
        $list_args['title_li']           = '';
        $list_args['hierarchical']       = 1;
        $list_args['use_desc_for_title'] = false;
        $list_args['walker']             = new BASEL_Walker_Category();
        
        if ( basel_is_shop_on_front() ) {
            $shop_link = home_url();
        } else {
            $shop_link = get_post_type_archive_link( 'product' );
        }
        include_once( WC()->plugin_path() . '/includes/walkers/class-product-cat-list-walker.php' );
        
        if( is_object( $current_cat ) && !get_term_children( $current_cat->term_id, 'product_cat' ) && $show_subcategories && !$show_categories_neighbors ) return;
        echo '<a href="#" class="basel-show-categories">' . esc_html__('Categories', 'basel') . '</a>';
        echo '<ul class="basel-product-categories">';
        
        echo '<li class="cat-link shop-all-link"><a href="' . esc_url( $shop_link ) . '">' . esc_html__('All', 'basel') . '</a></li>';
        if( $show_subcategories ) {
            basel_show_category_ancestors();
        } else {
            wp_list_categories( $list_args );
        }
        echo '</ul>';
    }

    Best Regards

Viewing 4 posts - 1 through 4 (of 4 total)