我有一个自定义帖子类型被称为产品与产品类别作为其分类名称。它包含每个都有子类别和帖子的类别。显示帖子数自定义帖子类型的子类别
我想仅显示子类别中所有帖子的计数。
这是我到目前为止有:
<?php
// POSTS LOOP
// Query
$args = array('post_type' => 'products' , 'orderby' => 'menu_order', 'order' => 'ASC' ,
'tax_query' => array(
array(
'taxonomy' => 'product_categories',
'terms' => array(14),
'include_children' => false
)
));
$query = new WP_Query($args);
// Post Counter
$term_id = 14;
$tax_name = 'product_categories';
$terms = get_terms($tax_name, array('parent' => 0));
$term_children = get_term_children($term_id,$tax_name);
$post_count = 0;
// Loop Structure
echo '<ul>';
while ($query->have_posts()) : $query->the_post();
echo '<li class="zazzoo-page">';
foreach($terms as $term) {
$term_children = get_term_children($term->term_id,$tax_name);
echo '<ul>';
foreach($term_children as $term_child_id) {
$term_child = get_term_by('id',$term_child_id,$tax_name);
$post_count = $term_child->count;
echo '<div class="zazzoo-counter">'. $post_count .' Designs</div>';
}
echo '</ul>';
} ?>
<div class="title-border"><div class="page-title"><?php the_title(); ?></div></div>
<div class="hovereffect">
<?php the_post_thumbnail('zazzoo-thumb', array('class' => 'responsive-img')); ?>
<div class="overlay">
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
</div>
</div>
<?php echo '</li>';
endwhile;
echo '</ul>';
wp_reset_query();
?>
以上是它目前看起来像一个图像。 小册子和卡片标签(其中每篇文章有4篇文章)是文章计数值应该显示的子类别,其余文章是帖子。
我还在学习WordPress主题开发,所以如果任何人都可以提供一些指导,将不胜感激。
所以,小册子和卡片标签是子类别,但地板图形,马克杯,记事本和贴纸是帖子? –
是的,这是正确的。所以我只想计算这些子类别中的帖子。 – Ragmah
使用您提供的代码,您似乎输出了6篇文章,并且没有任何类别或子类别(甚至小册子和卡片标签作为文章输出)。 –