自定义分类法的 Woocommerce 产品存档页面
Woocommerce Product Archive Page for Custom Taxonomy
我为 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>';
}
}
在 WP 管理员中,转到 设置>永久链接 并单击按钮 "Save Changes"。必须刷新重写规则。现在它就像一个魅力!
我为 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>';
}
}
在 WP 管理员中,转到 设置>永久链接 并单击按钮 "Save Changes"。必须刷新重写规则。现在它就像一个魅力!