首页 > 解决方案 > 分类学的帖子在wordpress中根本没有显示

问题描述

新手来了

我正在尝试显示我的帖子列表取决于类别。但它不显示我的帖子。我尝试了不同类型的数组,但没有运气。我将我的页面命名为 taxonomy-blog_category.php

我通过 site.com/blog_category/category 调用该页面

这是我当前的代码,我知道我很接近但无法弄清楚。

这是数组:

<div class="row">
    <?php $ctr = 1;
    $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
    $custom_args = array(
        'post_type'  => 'blog_post',
        'orderby'    => 'date',
        'order'      => 'DESC',
        'post_status' => 'publish',
        'posts_per_page' => 6,
        'paged'          => $paged,
        'tax_query'      => array(
            array(
                'taxonomy' => 'blog-category',
                'field'    => 'slug',
                'terms'    => array('business','people','technology'),
            ),
         ),
      );

这是我显示帖子的方式

$custom_query = new WP_Query( $custom_args ); ?>
<?php if ( $custom_query->have_posts() ) : ?>
<?php while ( $custom_query->have_posts() ) : $custom_query->the_post(); ?>
     <div class="col-md-4 text-center">
         <div class="content-container">
             <div class="wrap">
                 <figure class="tint t2">
                    <img src="<?php echo wp_get_attachment_url( get_post_thumbnail_id() ); ?>"  width="317px" height="240">
                 </figure>
             </div>
             <h2><?php the_title(); ?></h2>
             <h3>By <?php the_field('author'); ?> | <span><?php echo get_the_date(); ?></span></h3>
             <?php $content = get_field('content'); echo mb_strimwidth($content, 0, 200, '...');?>
         <div class="read-more-btn">
              <a href="<?php the_permalink(); ?>">read more</a>
         </div>
     </div>
 </div>

 <?php $ctr++; endwhile; ?>

我不知道这是否有必要,但这是我的分页代码:

<div class="pagination-holder">
    <ul class="pagination">
         <?php
             if (function_exists(custom_pagination)) {
                  custom_pagination($custom_query->max_num_pages,"",$paged);
             }
        ?>
        <?php wp_reset_postdata(); ?>
        <?php else:  ?>
            <p><?php _e( 'Sorry, no posts matched your criteria.' ); ?></p>
        <?php endif; ?>   
     </ul>
</div>

标签: phpwordpress

解决方案


推荐阅读