【问题标题】:WooCommerce category and sub category loopsWooCommerce 类别和子类别循环
【发布时间】:2016-09-20 23:15:18
【问题描述】:

在构建 WooCommerce 网站时,他们可以非常轻松地在存档和类别页面上显示类别和子类别。

但是有谁知道是否可以将类别/子类别列表添加到(内容单一产品)页面模板?

我的商店只有少量产品,我们希望用户能够从侧面菜单中快速选择,而不是在存档页面和产品页面之间来回切换。

感谢任何可以提供帮助的人。

【问题讨论】:

  • 最好的办法是使用小部件栏吗?您想在哪里显示它们以及如何显示(请提供更多详细信息)?在 content-single-product 页面上,它将仅显示与显示的产品相关的类别和子类别(一个产品 ID)......
  • “在构建 WooCommerce 网站时,他们使在存档和类别页面上显示类别和子类别变得非常容易。”有人能这么好心地指出我在哪里以及如何添加类别页面上带有产品类别的侧边栏?我在主商店页面上有类别侧边栏,但是当我转到子类别时 - 带有类别列表的侧边栏消失了。任何链接..任何东西都会有帮助。在整个stackoverflow上没有一个解释..

标签: woocommerce categories


【解决方案1】:
$prod_cat_args = array(
  'taxonomy'     => 'product_cat', //woocommerce
  'orderby'      => 'name',
  'empty'        => 0
);

$woo_categories = get_categories( $prod_cat_args );

foreach ( $woo_categories as $woo_cat ) {
    $woo_cat_id = $woo_cat->term_id; //category ID
    $woo_cat_name = $woo_cat->name; //category name

    $return .= '<a href="' . get_category_link( $woo_cat_id ) . '">' . $woo_cat_name . '</a>';
}
【解决方案2】:
$prod_cat_args = array(
'posts_per_page'   => 5,
    'offset'           => 0,
    'category'         => '',
    'category_name'    => '',
    'orderby'          => 'date',
    'order'            => 'DESC',
    'include'          => '',
    'exclude'          => '',
    'meta_key'         => '',
    'meta_value'       => '',
    'post_type'        => 'post',
    'post_mime_type'   => '',
    'post_parent'      => '',
    'author'       => '',
    'post_status'      => 'publish',
    'suppress_filters' => true 
);
 you can also edit all fields try this

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多