我有以下查询输出我的自定义帖子类型名为STORIES的类别列表。自定义帖子类型Wordpress查询按类别
<?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?
任何想法?无法获得任何解决方案。
我有以下查询,但它列出了所有的类别和他们内的所有帖子。我如何修改它只显示我所在页面的帖子?
<?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;
}
}
?>
这将输出所有类别及其帖子。我只想列出我所在页面的内容。如果我在APPLES页面 - 我只想列出APPLES帖子。而不是每个类别的附加链接。 – lowercase
您是否创建了模板或自定义分类模板..? – vrajesh
根据你的分类标准你的文件名是什么? – vrajesh