woocommerce产品类别没有以类别子类别的正确顺序显示

时间:2015-12-17 05:29:47

标签: php wordpress

这是我用来显示产品类别的代码,但显示的类别不是为了例如。

类别  -subcategory  --subcagergory  ---子类别 类别   -subcategory

这就是它

<?php            
    $args = array(          
        'number'     => $number,
        'orderby'    => 'name',
        'order'      => 'ASC',
        'hide_empty' => $hide_empty,
        'include'    => $ids
    );
    $product_categories = get_terms( 'product_cat', $args );
    $count = count($product_categories);
    if ( $count > 0 ){
        foreach ( $product_categories as $product_category ) {
            echo '<h4><a href="' . get_term_link( $product_category ) . '">' . $product_category->name . '</a></h4>';
            $args = array(
                'posts_per_page' => -1,
                'tax_query' => array(
                    'relation' => 'AND',
                    array(
                        'taxonomy' => 'product_cat',
                        'field' => 'slug',
                        // 'terms' => 'white-wines'
                        'terms' => $product_category->slug
                    )
                ),
                'post_type' => 'product',
                'orderby' => 'title,'
            );
            $products = new WP_Query( $args );
            echo "<ul>";
            while ( $products->have_posts() ) {
                $products->the_post();
            ?>
                <li>
                    <a href="<?php the_permalink(); ?>">
                        <?php the_title(); ?><br>
                        <a href="<?php the_field('product_tech_spec_sheet');?>">-Product Tech Spec Sheet</a>;<br>
                        <a href="<?php the_field('producProduct Brochuret_brochure'); ?>">-Product Brochure</a>;
                    </a>
                </li>
            <?php
            }
            echo "</ul>";
        }
    } 
?>

0 个答案:

没有答案