2

我正在调用 Woocommerce 类别的列表,并试图让它们以自定义的、直截了当的顺序显示,但无济于事。通常的 'orderby' => 'menu_order' 不起作用。下面的代码:

         <?php
            $args=array(
                'orderby' => 'menu_order',
                'order' => 'ASC',
                'child_of' => 13,
                'hide_empty' => 0,
                'taxonomy' => 'product_cat'
            );
            $categories=get_categories($args);
                foreach($categories as $category) {  
                    echo "<li class='filter-option " . $category->slug . "'><a href='#' data-filter-value='." . $category->slug . "'>";
                    echo $category->name;
                    echo "</a></li>";
                } 
            ?>

任何帮助将不胜感激

4

2 回答 2

8

您正在寻找 get_categories() 参数的参数是

'menu_order' => 'asc'

所以例如。我返回前三个根 Woocommerce 类别(不包括未分类)的函数如下所示:

// load first three categories from Woocommerce
function my_get_woocommerce_categories() {
	$args = array(
		'taxonomy' => 'product_cat',
		'parent' => 0,
		'hide_empty' => false,
		'number' => 3,
		'show_uncategorized' => false,
		'menu_order' => 'asc',
	);

	$categories = get_categories( $args );

	return $categories;
}

于 2015-05-13T02:07:49.743 回答
0

Please try this...

<?php $wcatTerms = get_terms('product_cat', array('hide_empty' => 0, 'orderby' => 'ASC',  'parent' =>0)); //, 'exclude' => '17,77'
                foreach($wcatTerms as $wcatTerm) : 
                    $wthumbnail_id = get_woocommerce_term_meta( $wcatTerm->term_id, 'thumbnail_id', true );
                    $wimage = wp_get_attachment_url( $wthumbnail_id );
                ?>
                <ul>
                    <li class="libreak"><?php if($wimage!=""):?><img src="<?php echo $wimage?>"><?php endif;?></li>
                    <li>
                        <a href="<?php echo get_term_link( $wcatTerm->slug, $wcatTerm->taxonomy ); ?>"><?php echo $wcatTerm->name; ?></a>
                        <ul class="wsubcategs">
                        <?php
                        $wsubargs = array(
                           'hierarchical' => 1,
                           'show_option_none' => '',
                           'hide_empty' => 0,
                           'parent' => $wcatTerm->term_id,
                           'taxonomy' => 'product_cat'
                        );
                        $wsubcats = get_categories($wsubargs);
                        foreach ($wsubcats as $wsc):
                        ?>
                            <li><a href="<?php echo get_term_link( $wsc->slug, $wsc->taxonomy );?>"><?php echo $wsc->name;?></a></li>
                        <?php
                        endforeach;
                        ?>  
                        </ul>
                    </li>
                </ul>
            <?php 
                endforeach; 
            ?>
于 2013-11-26T04:45:58.403 回答