我有以下查询,该查询为名为STORIES的自定义帖子类型输出类别列表。
<?php
$taxonomy = 'story-category';
$tax_terms = get_terms($taxonomy);
?>
<?php
foreach ($tax_terms as $tax_term) {
echo '<div class="category-grid-box">
<div class="category-grid-content">' . '<a href="' . esc_attr(get_term_link($tax_term, $taxonomy)) . '" title="' . sprintf( __( "View all posts in %s" ), $tax_term->name ) . '" ' . '>' . $tax_term->name.'</a> </div>
</div> ';
}
?>
这会输出我的类别的链接列表,并且效果很好。
我的问题是,我不知道如何在下一页上写查询,该查询将列出该所选类别中的所有帖子。
所以我的查询列出了类别...-苹果-橙子-香蕉
如果您单击Apples并转到该页面,我将使用什么查询来列出所有具有APPLES类别的故事?
有任何想法吗?无法获得任何解决方案。
我有以下查询,但它列出了所有类别以及其中的所有帖子。如何修改它以仅显示我所在页面的帖子?
<?php
$custom_terms = get_terms('story-category');
foreach($custom_terms as $custom_term) {
wp_reset_query();
$args = array('post_type' => 'stories',
'tax_query' => array(
array(
'taxonomy' => 'story-category',
'field' => 'slug',
'terms' => $custom_term->slug,
),
),
);
$loop = new WP_Query($args);
if($loop->have_posts()) {
echo '<h2>'.$custom_term->name.'</h2>';
while($loop->have_posts()) : $loop->the_post();
echo '<p><a href="'.get_permalink().'">'.get_the_title().'</a></p>';
endwhile;
}
}
?>
您可以为自定义帖子创建自定义分类模板:LINK
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句