php - 分类学的帖子在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>
解决方案
推荐阅读
- butterworth - 巴特沃斯函数
- java - Javafx 在画布上绘图时甚至会滞后
- java - 与 cli 应用程序交互的 Spring Rest API
- swift - SwiftUI ForceTouch 风格弹窗
- ios - 为什么 CGContext 在 iOS 14 的 UITableViewCell 中不起作用?
- html - 如何强制将 br 分隔的链接列表显示为项目符号列表?
- html - How can I display html image in a container the same way css displays background-image?
- python - 从页面获取脚本标签的内容并使用 python 将其保存为 javascript 文件格式
- keycloak - 使用 keycloak rest api 更新用户的问题
- android - 深度链接在 Chrome 移动浏览器中不起作用