【发布时间】:2015-10-13 15:08:14
【问题描述】:
我需要使用 slug 订购“$product->get_categories()”的结果。
模板使用此代码:
$cat_count = sizeof( get_the_terms( $post->ID, 'product_cat' ) );
//And after...
<?php echo $product->get_categories( ', ', '<span class="posted_in">' . _n( 'Category:', 'Categories:', $cat_count, 'woocommerce' ) . ' ', '</span>' ); ?>
我在教程中看到,我可以使用此代码,但不起作用(在functions.php中):
function wptt_cat_order( $args ){
$args['orderby'] = 'slug';
$args['order'] = 'ASC';
return $args;
} // wptt_cat_order
add_filter( 'woocommerce_product_subcategories_args', 'wptt_cat_order' );
我的另一个问题是(但并不比另一个问题重要),为什么他在“_n()”函数中使用 $cat_count 而不是“get_the_terms( $post->ID, 'product_cat' )”? first 只是一个数字 O_O。
【问题讨论】:
标签: php wordpress woocommerce