簡體   English   中英

按名稱依次顯示類別 - wordpress

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM