2016-04-29 106 views
0

我使用Wordpress的Custom Post Type UI插件創建了一個名爲Resource Library的自定義發佈類型和一個名爲Resource Categories的自定義Taxonomy。我無法查詢分類標準頁面模板上的類別。如果有人能幫我解決這個問題,我將非常感激。使用CPT UI顯示分類頁面

這裏是我在我的分類,資源categories.php文件中的代碼:

<?php $args = array(
    'post_type' => 'resource-library', 
    'tax_query' => array(
     array(
      'taxonomy' => 'resource-categories', 
      'field' => 'slug',  
      'terms' => 'data-sheets', 
     ), 
    ), 
); $query = new WP_Query($args); 
?> 

<?php while (have_posts()) : the_post(); ?> 

<div class="blog-post-wrap"> 
<a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"> 
<div class="post-thumb blog-index"> 
<?php 
if (has_post_thumbnail()) { // check if the post has a Post Thumbnail assigned to it. 
    the_post_thumbnail('large'); 
} 
?> 
</div> 
<div class="title-meta-wrap"> 

<?php if (strlen($post->post_title) > 75) { 
echo substr(the_title($before = '', $after = '', FALSE), 0, 75) . '...'; } else { 
the_title(); 
} ?> 
</a> 
<p><span class="theauthor"><?php the_date(); ?> <span style="color:#EC7906;">/</span><?php the_author(); ?> </span></p> 

</div> 
</div> 
<?php endwhile; ?> 

回答

0

你正在創建$查詢對象,但不使用該對象在循環。所以,用這段代碼替換你的循環。

<?php while($query->have_posts()): $query->the_post(); ?> 

然後您的查詢將有數據,您可以根據您的需要使用您的數據。希望有幫助