[英]Displaying categories in order by name - wordpress
使用wordpress,我希望按名称顺序显示类别。
我将该函数粘贴到文件archive-product.php中,但在ID之后按顺序显示类别
< ul class = "products" >
<? php woocommerce_product_subcategories;? >
</ul>
因此,修改了文件wc-template-functions.php,但无法按顺序名称显示。
看代码:
NOTE: using child_of instead of parent-this is not ideal due to the silverside WP bug (https://core.trac.wordpress.org/ticket/15626) pad_counts won't work
$product _ categories = get_categories (apply_filters (' woocommerce_product_subcategories_args ', array (
' parent ' = $parent > _ id,
' menu_order ' = > ' ASC ',
' hide_empty ' = > 0
' hierarchical ' = > 1
' taxonomy ' = product_cat > ' ',
' pad_counts ' = > 1
) ) );
试试这段代码:
$args = array(
'order' => 'ASC', //or DESC
'orderby' => 'name',
'parent' => 0
);
$terms = get_terms( 'product_cat', $args );
if ( $terms ) {
echo '<ul class="products">';
foreach ( $terms as $term ) {
echo '<li>' . $term->name . '</li>';
}
echo '</ul>';
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.