我不知道你到底想做什么。下面是使用偏移量的示例。对于一个类别,将显示第一篇文章,该文章可以具有唯一的HTML结构/布局。
然后显示其余的帖子,但搜索会忽略第一个结果,并将其偏移一个项目。这对你有意义吗?
如果你正在寻找学习如何开发主题的好视频教程,请看this. 还有一个是关于存档和自定义查询的,强烈建议使用。
<?php
// Get first post from category
$args = array(
\'category_name\' => \'the_name_of_the_category\',
// Display only the first post on this category page
\'posts_per_page\' => 1
);
$search = new WP_Query( $args );
if($search->have_posts()) :
while($search->have_posts()) : $search->the_post();
post_class();
the_content();
endwhile;
endif;
wp_reset_postdata();
// Get the ramaining posts but start at 2nd position
$args = array(
\'category_name\' => \'the_name_of_the_category\',
\'posts_per_page\' => 5,
// So here we start with the 2nd post in the search and not in the First
// the offset in the arguments for this post query is one
\'offset\' => 1
);
$search = new WP_Query( $args );
if($search->have_posts()) :
while($search->have_posts()) : $search->the_post();
post_class();
the_content();
endwhile;
endif;
wp_reset_postdata();
?>