【问题标题】:Display taxonomy page using CPT UI使用 CPT UI 显示分类页面
【发布时间】:2016-04-29 20:23:23
【问题描述】:

我使用 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; ?>

【问题讨论】:

    标签: php wordpress


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-11-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多