2016-04-29 113 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(); ?> 

然后您的查询将有数据,您可以根据您的需要使用您的数据。希望有帮助