【发布时间】:2015-11-09 21:27:57
【问题描述】:
我必须将类别命名为“Collectie”和“Shop”,我想要的是两个类别的子类别的不同布局。
我已经尝试过这样的 template_include 函数:
function lab5_template_include( $template ) {
if ( category_has_children('collectie')) {
$template = get_stylesheet_directory() . '/woocommerce/archive-product-collectie.php';
}elseif ( is_product_category('shop')) {
$template = get_stylesheet_directory() . '/woocommerce/archive-product-shop.php';
}
return $template;
}
我该怎么做?
编辑
我用https://wordpress.org/support/topic/different-page-layouts-for-category-vs-subcategory的解决方案解决了
我在 taxonomy-product_cat.php 中添加了下一行
// We need to get the top-level category so we know which template to load.
$get_cat = $wp_query->query['product_cat'];
// Split
$all_the_cats = explode('/', $get_cat);
// How many categories are there?
$cat_count = count($all_the_cats);
//
// All the cats say meow!
//
// Define the parent
$parent_cat = $all_the_cats[0];
// Collectie
if ( $parent_cat == 'collectie' ) woocommerce_get_template( 'archive-product-collectie.php' );
// Shop
elseif ( $parent_cat == 'shop' ) woocommerce_get_template( 'archive-product.php' );
【问题讨论】:
标签: php wordpress woocommerce wordpress-theming