使用CPT UI显示分类法页面

时间:2016-04-29 20:23:24

标签: php wordpress

我使用wordpress的自定义帖子类型UI插件创建了一个名为资源库的自定义帖子类型和一个名为资源类别的自定义分类。我在分类页面模板上查询类别时遇到问题。如果有人可以帮我解决这个问题,我将非常感激。

以下是我在taxonomy-resource-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; ?>

1 个答案:

答案 0 :(得分:0)

您正在创建$ query对象但不在循环中使用该对象。所以,用这段代码替换你的循环。

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

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

相关问题