【发布时间】:2015-07-13 08:47:56
【问题描述】:
我想在主页上仅显示 3 个选定类别中的前 3 个帖子。所有分类页面都可以像往常一样显示默认的10个。
这是我尝试过但不起作用的查询:
$the_query= new WP_Query( 'cat=1,2,3&posts_per_page=3' );
还有循环:
if ( $paged == 1 ) {
get_template_part( 'includes/featured' );
} else {
$page_title = sprintf( __( 'Recent Posts - page %d', 'opti' ), $paged );
}
if ( have_posts() ) {
?>
<div id="recent-posts" class="<?php echo $recent_colwidth; ?>">
<h3><?php echo $page_title; ?></h3>
<ul id="recent-excerpts">
<?php
while( have_posts() ) {
the_post();
if ( $post->ID != $ignore_post ) {
get_template_part( 'content', 'home-loop' );
}
}
?>
</ul>
<?php
get_template_part( 'includes/pagination' );
?>
只需要一点帮助就可以将它们组合在一起。如果可能,我还希望帖子在作者旁边显示类别。
【问题讨论】:
-
您将不得不使用 WP_Query 三次,每个类别一次。
标签: wordpress loops categories posts