[英]Custom Post Type taxonomy page still showing all posts
我有一个自定义帖子类型“项目”分类法的子导航,称为“类型”:
<?php $args = array( 'post_type' => 'projects');
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $terms = get_terms('type');
$currentterm = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'taxonomy' ) );
echo '<ul class="sub-nav-menu">';
foreach ($terms as $term) {
$class = $currentterm->slug == $term->slug ? 'live' : '' ;
echo '<li><a href="'.get_term_link($term).'" class="'. $class .'">'.$term->name.'</a></li>';
}
echo '</ul>'; ?>
<?php endwhile; ?>
<?php endif; ?>
单击分类法时,将带您到分类法页面taxonomy-type.php。
尽管此页面仍显示所有自定义帖子类型,而不仅仅是当前分类页面的类型。
<?php $args = array( 'post_type' => 'projects');
$the_query = new WP_Query( $args ); ?>
<?php if ( $the_query->have_posts() ) : ?>
<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php $terms = get_terms('type'); ?>
<a href="<?php the_permalink() ?>">
<h3><?php the_title(); ?></h3>
</a>
<?php wp_reset_postdata(); ?>
<?php endwhile; ?>
<?php endif; ?>
如何修改循环以仅过滤“类型”分类法的当前分类法帖子?
您可以在taxonomy- {post_type} .php中按分类法获取帖子列表。默认情况下,此文件中的gt列表为指定分类法。
在当前活动主题文件夹中创建类似此文件的文件,并使用以下代码,
<?php
if ( have_posts() ) {
while ( have_posts() ) {
the_post();
//
// Post Content here
//
} // end while
} // end if
?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.