Php 更改WordPress循环以显示类别
我有一个简单的WordPress循环来获取100篇最新帖子。我如何根据我所属的类别更改此选项以动态显示帖子Php 更改WordPress循环以显示类别,php,wordpress,loops,Php,Wordpress,Loops,我有一个简单的WordPress循环来获取100篇最新帖子。我如何根据我所属的类别更改此选项以动态显示帖子 <?php // the query $wpb_all_query = new WP_Query(array( 'post_type' => 'post', 'post_status' => 'publish', 'post-no' => 100)); ?> <?php
<?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 : ?>
"
alt=”“/>
如果您的意思是您在类别存档页面上,则此代码将起作用:
// 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));
你好@katie,很抱歉耽搁了,我是说当我在一个类别中只显示类别帖子时。我会试试你的答案,看看我能做些什么