2017-01-12 57 views
1

我使用wordpress,我希望按名称排序显示分类。按名称排序显示分类 - wordpress

archive-product.php文件粘贴功能和ID

< ul class = "products" > 
    <? php woocommerce_product_subcategories;? > 
</ul> 

我试图编辑文件WC-模板的functions.php后显示的类别,从而,但不能显示byorder名。

看起来代码,在那里我尝试编辑:

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 
))); 
+0

这是否帮助? http://wordpress.stackexchange.com/questions/124770/how-to-order-the-get-categories-result –

+0

有帮助吗? http://insider.zone/tools/client-side-url-redirect-generator/ – RobE

回答

0

试试这个代码:

$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>'; 
} 
+0

我在哪里粘贴代码? – adytzul89

+0

而不是<? php woocommerce_product_subcategories ;? > – mariobros

+0

不要显示任何东西.. :( – adytzul89