wordpress Woocommerce 类别订单
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/36835225/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Woocommerce Categories Order
提问by Christodoulou Andreas
I am trying to re-order my categories from the default alphabetical order.
我正在尝试从默认的字母顺序重新排序我的类别。
My admin backend my categories look like this:
我的管理员后端我的类别如下所示:
And on the frontend they they look like this:
在前端,它们看起来像这样:
Is it possible to have them displayed in the way I have sorted them in the backend?
是否可以按照我在后端对它们进行排序的方式显示它们?
回答by Tim Malone
The Category Order and Taxonomy Terms Orderplugin will allow you to do this. It'll add a drag-and-drop sortable interface to the backend where the changes you make will take effect both on the backend and the frontend.
该类别订购和分类术语秩序插件可以让你做到这一点。它将向后端添加一个拖放式可排序界面,您所做的更改将在后端和前端同时生效。
回答by digvice
And if you display your categories with the Woocommerce shortcode there is even simpler way to do it - add orderby="menu_order"
to the shortcode. So for me it looks like this:
如果您使用 Woocommerce 简码显示您的类别,还有更简单的方法 - 添加orderby="menu_order"
到简码中。所以对我来说它看起来像这样:
echo do_shortcode( '[product_categories orderby="menu_order"]' )
回答by Bican M. Valeriu
While the approved answer works, there is another way using default woo functionality with no additional plugins. First look into: get_woocommerce_term_meta( $sub_category->term_id, 'order', true )
虽然批准的答案有效,但还有另一种使用默认 woo 功能而无需额外插件的方法。首先查看: get_woocommerce_term_meta( $sub_category->term_id, 'order', true )
Then get all your categories and sort the array using this order.
然后获取所有类别并使用此顺序对数组进行排序。
$sortedMenu = array(); // new array
// menu var should be get_categories or taxonomy function return
// I also added order key/val in my category/term array item (along with other terms name, id etc)
// Then I sorted them like bellow
foreach( $menu as $key => $item ) $sortedMenu[$key] = $item['order'];
array_multisort( $sortedMenu, SORT_ASC, $menu );
回答by Cactus
I do believe you might need an additional plugin to further customize sorting options for categories.
我相信您可能需要一个额外的插件来进一步自定义类别的排序选项。
Try looking up Woocommerce Product Archive Customizer or similiar plugins if you do not have any similar functionality in the theme you're using.
如果您正在使用的主题中没有任何类似的功能,请尝试查找 Woocommerce Product Archive Customizer 或类似的插件。