我想运行循环,以便它只从一个特定类别检索帖子,只输出4篇帖子,并排除最新的帖子。
要仅查询一个类别,我发现:
<?php query_posts(\'cat=1\'); ?>
<?php if ( have_posts() ) : while (have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
为了排除最新的帖子并只输出4篇帖子,我发现:
<?php query_posts(\'posts_per_page=4&offset=1\'); ?>
<?php if (have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php the_content(); ?>
<?php endwhile; endif; ?>
然而,我不知道如何将两者结合起来。我可以这样做吗,或者有更好的方法吗?
最合适的回答,由SO网友:Rishabh 整理而成
Try this code
global $myOffset;
$myOffset = 1;
$paged = get_query_var(\'paged\') ? get_query_var(\'paged\') : 1; //Use \'page\' instead of \'paged\' if you are on home page
$args = array(
\'post_type\' => \'post\',
\'cat\'=> 1, //Selecting post category by ID to show
\'posts_per_page\' => 4, //No. of posts to show
\'offset\' => $myOffset, //Eexcluding latest post
\'paged\' => $paged //For pagination
);
$loop = new WP_Query( $args );
while ( $loop->have_posts() ) : $loop->the_post();
the_content(__(\'Continue Reading\'));
endwhile;