如何在 wordpress 循环中显示一个或另一个类别的帖子?
How do I display posts from one category or another in wordpress loop?
我正在尝试创建一个 wordpress 循环来显示来自类别 1 或类别 2 的帖子。不必两者都是。我目前只显示两个类别的帖子。我在网上找遍了,但找不到我要找的东西。
这是我的循环代码,目前只显示分配给两个类别的帖子。
<?php
// Example argument that defines three posts per page.
$args = array(
'posts_per_page' => 3,
'cat' => 1,
'cat' => 154
);
// Variable to call WP_Query.
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
$i = 0;
// Start the Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
if ( $i == 0 ) : ?>
//loop content here
<?php endif;
// End the Loop
$i++;
endwhile;
else:
// If no posts match this query, output this text.
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
wp_reset_postdata();
?>
您尝试过使用 category__in 参数吗?像这样:
category__in => array(1, 154)
我正在尝试创建一个 wordpress 循环来显示来自类别 1 或类别 2 的帖子。不必两者都是。我目前只显示两个类别的帖子。我在网上找遍了,但找不到我要找的东西。
这是我的循环代码,目前只显示分配给两个类别的帖子。
<?php
// Example argument that defines three posts per page.
$args = array(
'posts_per_page' => 3,
'cat' => 1,
'cat' => 154
);
// Variable to call WP_Query.
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) :
$i = 0;
// Start the Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
if ( $i == 0 ) : ?>
//loop content here
<?php endif;
// End the Loop
$i++;
endwhile;
else:
// If no posts match this query, output this text.
_e( 'Sorry, no posts matched your criteria.', 'textdomain' );
endif;
wp_reset_postdata();
?>
您尝试过使用 category__in 参数吗?像这样:
category__in => array(1, 154)