[英]Change WordPress loop to show category
我有一个简单的 WordPress 循环来获取 100 个最新帖子。 如何更改此设置以根据我所在的类别动态显示帖子?
<?php
// the query
$wpb_all_query = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'post-no' => 100));
?>
<?php if ($wpb_all_query->have_posts()) :
while ($wpb_all_query->have_posts()) : $wpb_all_query->the_post(); ?>
<img class="card-img-top bottom-line mb-2 lozad "
data-src="<?php the_post_thumbnail_url(); ?>"
alt="<?php the_title(); ?>"/>
<?php endwhile; ?>
<?php else : ?>
如果您的意思是您在类别存档页面上,那么此代码将起作用:
// gets the category information from the archive page
$cat = get_the_category();
// the query
$wpb_all_query = new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
// queries for posts that have that category
'cat' => $cat[0]->cat_ID,
'post-no' => 100));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.