在WooCommerce中,我使用以下代码为我的产品创建了一个完美的自定义分类:
// Register Custom Taxonomy
function ess_custom_taxonomy_Item() {
$labels = array(
'name' => 'Collections',
'singular_name' => 'Collection',
'menu_name' => 'Collections',
'all_items' => 'All Collections',
'parent_item' => 'Parent Collection',
'parent_item_colon' => 'Parent Collection:',
'new_item_name' => 'New Collection Name',
'add_new_item' => 'Add New Collection',
'edit_item' => 'Edit Collection',
'update_item' => 'Update Collection',
'separate_items_with_commas' => 'Separate Collection with commas',
'search_items' => 'Search Collections',
'add_or_remove_items' => 'Add or remove Collections',
'choose_from_most_used' => 'Choose from the most used Collections',
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'public' => true,
'show_ui' => true,
'show_admin_column' => true,
'show_in_nav_menus' => true,
'show_tagcloud' => true,
);
register_taxonomy( 'collection', 'product', $args );
}
add_action( 'init', 'ess_custom_taxonomy_item', 0 );
我现在需要创建一个完全模拟标准的woocommerce“商店”页面(显示每个顶级类别)的页面,但显示此分类而不是类别。怎么做到这一点?我想象要么在WooCommerce中复制商店页面模板并替换一些(?)调用,或者创建一个Woo短代码的副本(可能来自插件?)。
*另外,我已经使用ACF为每个新的'集合'分类标准分配了一个图像字段,我想我需要进入前端才能实现上述目标。
非常感谢。
答案 0 :(得分:0)
最后,我设法通过复制和重命名主题页面模板,包括产品网格的标记,并抓住分类术语和ACF图像,如下所示。这里的foreach代码非常有用 - 希望这是对某人的使用。
<?php
// Get Terms for Custom Taxonomy
$taxonomy = 'collection';
$tax_terms = get_terms($taxonomy);
?>
<!-- Duplicated Product Grid Markup -->
<div class="col-sm-12">
<div class="row">
<ul class="products columns-4">
<div class="col-sm-4">
<?php
// Create grid item for each instance of the Custom Taxonomy
foreach ($tax_terms as $tax_term) {
echo '<li class="product-category product">';
echo '<a href="/collection/' . $tax_term->slug . '">';
// Grab & insert the ACF thumbnail 'collection_image'
$thumbnail = get_field('collection_image', $tax_term->taxonomy . '_' . $tax_term->term_id);
echo '<img src="' . $thumbnail . '" alt="' . $tax_term->name . '" width="300" height="300" />';
// Tie it all up
echo '<h3>' . $tax_term->name . '</h3>';
echo '</a></li>';
}
?>
</div>
</ul>
</div>
</div>