简体   繁体   English

用于自定义分类的 Woocommerce 产品存档页面

[英]Woocommerce Product Archive Page for Custom Taxonomy

I registered a custom taxonomy for WooCommerce products.我为 WooCommerce 产品注册了自定义分类法。 Additionally, I set up a page template to list up all entries of the custom taxonomy with taxonomy archive links.此外,我设置了一个页面模板来列出自定义分类法的所有条目以及分类法存档链接。 Now I have the problem, that the archive links are not working.现在我遇到了问题,存档链接不起作用。 I was expecting them to work similarly to the product category and product tag archive pages.我期待它们的工作方式类似于产品类别和产品标签存档页面。 Do I need to set up a custom archive page file or is there something missing in my code?我需要设置自定义存档页面文件还是我的代码中缺少某些内容? Thanks for any hint or help in advance!感谢您提前提供任何提示或帮助!

// 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>';
  }
}

In the WP admin go to Settings>Permalinks and click on the button "Save Changes" .在 WP admin 中,转到Settings>Permalinks并单击按钮“Save Changes” Rewrite Rules had to be flushed.必须刷新重写规则。 Now it works like a charm!现在它就像一个魅力!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM