2017-07-03 83 views
0

我有一个自定义后类型的“项目”分类学名为“类型”的子导航:自定义文章类型分类页面仍然显示的所有帖子

 <?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; ?> 

当分类点击它把你的分类页面分类-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; ?> 

我该如何修改循环以仅过滤“类型”分类标准的当前分类标准?

回答

1

您可以通过分类学中的分类学获得发布列表 - {post_type} .php在此文件中,默认为指定分类的gt列表。

创建类似这样的文件在当前活动主题文件夹,使用下面的代码,

<?php 
if (have_posts()) { 
    while (have_posts()) { 
     the_post(); 
     // 
     // Post Content here 
     // 
    } // end while 
} // end if 
?> 
相关问题