2017-07-03 89 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 
?> 
相關問題