它是必需的,像/catalog/category/subcategory/my_mark/这样的自定义url显示该子类别的产品(过滤my_mark存在),就像在/catalog/category/subcategory/的情况下一样。我写了一个插件,并试图有条件地改变逻辑通过改变$wp_query变量在函数:
load_template, get_header
但是,它仍然不是相同的模板顺序,所以问题是如何(和/或在哪里)改变$wp_query只是为了显示正确的模板顺序的结果,因为它将在正常的子类别模板视图?
通过过滤template_include函数,之前调试正确的模板文件使用。下面是代码,也许会对别人有所帮助:
add_filter('template_include', 'seo_includer' );
function seo_includer($args) {
global $wp_query;
if(<my_condition>)
{
if (true) {
status_header( 200 );
$wp_query->is_404=false;
}
$args = array(
'posts_per_page' => 777,
'product_cat' => $category['slug'],
'post_type' => 'product',
'orderby' => 'meta_value_num',
);
$wp_query = new WP_Query($args);
return ABSPATH.'wp-content/themes/<mytheme>/woocommerce/taxonomy-product_cat.php';
}
return $args;
}