品牌自定义分类的 Woocommerce 产品档案页面

问题描述 投票:0回答:1

我为 WooCommerce 产品注册了自定义分类法。此外,我设置了一个页面模板来列出自定义分类的所有条目以及分类存档链接。现在我遇到了问题,存档链接不起作用。我期望它们的工作方式与产品类别和产品标签存档页面类似。我是否需要设置自定义存档页面文件,或者我的代码中是否缺少某些内容?感谢您提前提供任何提示或帮助!

// Register Custom Taxonomy
function ffos_custom_taxonomy_Brand()  {

$labels = array(
    'name'                       => 'Brands',
    'singular_name'              => 'Brand',
    'menu_name'                  => 'Brands',
    'all_brands'                  => 'All Brands',
    'parent_item'                => 'Parent Brand',
    'parent_item_colon'          => 'Parent Brand:',
    'new_item_name'              => 'New Brand Name',
    'add_new_item'               => 'Add New Brand',
    'edit_item'                  => 'Edit Brand',
    'update_item'                => 'Update Brand',
    'separate_items_with_commas' => 'Separate Brand with commas',
    'search_items'               => 'Search Brands',
    'add_or_remove_items'        => 'Add or remove Brands',
    'choose_from_most_used'      => 'Choose from the most used Brands',
);
$args = array(
    'labels'                     => $labels,
    'hierarchical'               => true,
    'public'                     => true,
    'show_ui'                    => true,
    'show_admin_column'          => true,
    'show_in_nav_menus'          => true,
);
register_taxonomy( 'product_brand', 'product', $args );

}

add_action( 'init', 'ffos_custom_taxonomy_Brand', 0 );
$args = array(
  'orderby'    => 'name',
  'order'      => ASC,
  'hide_empty' => true,
);

$product_brand = get_terms( 'product_brand', $args );

if ( $product_brand && ! is_wp_error( $product_brand ) ) {

  foreach ($product_brand as $brand) {

    $brand_logo = get_field('brand_logo', $brand);
    $brand_title = $brand->name;
    $brand_link = get_term_link( $brand );

    echo '<div class="small-12 medium-4 large-2 columns" >';
    echo '<a href="'.$brand_link.'">';
    echo '<div class="brand_logo" style="background-image:url('.$brand_logo.');" alt="'.$brand_title.'"></div>';
    echo '</a>';
    echo '</div>';
  }
}
php wordpress woocommerce custom-taxonomy
1个回答
2
投票

在 WP 管理中,转到 设置>永久链接,然后单击按钮 “保存更改”。重写规则必须被刷新。现在它就像一个魅力!

© www.soinside.com 2019 - 2024. All rights reserved.