Info about my setup:
<我有一个名为“治疗”的自定义贴子类型,每个治疗最多可分为3个分类类型-治疗类别-“美容沙龙”、“皮肤病”和“spadays”,它们下面有许多不同的类别What I am trying to achieve:
在治疗类别存档页面上显示治疗,但按品牌分类法进行划分,还包括类别内未附加到品牌分类法的治疗。因此,归档页面的外观如下所示:Treatment Category Title
Brand 1
<治疗A治疗B治疗C治疗Brand 2
<治疗D(无品牌)我对治疗J进行了分类。php模板在每个分类页面上都会处理这个问题,但是。。。
My issues are:
1) 我无法找到阻止显示空治疗类别标题的方法。我想我需要在某处插入foreach或IF语句,或者可能更改$args数组,以便只返回中包含处理的类别。我尝试过包含hide\\u空语句,但这似乎也不起作用。2) 当我按品牌分类法设置查询时,我无法显示未附加到任何品牌的治疗方法。也许我需要两个循环?
这是我的密码,有什么帮助吗?
<?php
// grab current page info
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
// fetch the terms for brands tax
$terms = get_terms( \'brands\', array(
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
) );
the_archive_title( \'<h1 class="page-title">\', \'</h1>\' );
// now run a query for each brand
foreach( $terms as $term ) {
$args = array(
\'post_type\' => \'treatments\',
\'nopaging\' => true,
\'orderby\' => \'title\',
\'order\' => \'ASC\',
\'hide_empty\' => true,
\'tax_query\' => array(
\'relation\' => \'AND\',
array(
\'taxonomy\' => \'brands\',
\'terms\' => $term->slug,
\'field\' => \'slug\',
\'operator\' => \'IN\'
),
array(
\'relation\' => \'OR\',
array(
\'taxonomy\' => \'beautysalon\',
\'terms\' => $queried_object->slug,
\'field\' => \'slug\',
\'operator\' => \'IN\'
),
array(
\'taxonomy\' => \'skinclinic\',
\'terms\' => $queried_object->slug,
\'field\' => \'slug\',
\'operator\' => \'IN\'
),
array(
\'taxonomy\' => \'spadays\',
\'terms\' => $queried_object->slug,
\'field\' => \'slug\',
\'operator\' => \'IN\'
),
)
)
);
$query = new WP_Query( $args );
// output the term name in a heading tag
echo\'<h2>\' . $term->name . \'</h2>\';
// output the post titles in a list
echo \'<ul>\';
while ( $query->have_posts() ) : $query->the_post(); ?>
<li id="post-<?php the_ID(); ?>">
<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
</li>
<?php endwhile;
echo \'</ul>\';
wp_reset_postdata();
} ?>