我正在使用query_posts( \'offset=1\' );
将第一篇文章从循环中排除。但是,如果第一个帖子是粘性帖子,则会显示该帖子,而第二个(非粘性)帖子不会显示。
是否有任何方法可以隐藏第一篇帖子,无论它是否有粘性?我不能使用ignore_sticky_posts
因为我只想隐藏第一个。
谢谢你的帮助!
我正在使用query_posts( \'offset=1\' );
将第一篇文章从循环中排除。但是,如果第一个帖子是粘性帖子,则会显示该帖子,而第二个(非粘性)帖子不会显示。
是否有任何方法可以隐藏第一篇帖子,无论它是否有粘性?我不能使用ignore_sticky_posts
因为我只想隐藏第一个。
谢谢你的帮助!
你真的不需要“排除”任何东西。只需利用内置的循环跟踪。WP_Query
会“记住”你在哪里停下来的。例如:
if (have_posts()) {
while (have_posts()) {
the_post();
echo \'firstpost##\';
the_content();
echo \'##endfirstpost\';
break;
}
}
// do some other stuff
if (have_posts()) {
while (have_posts()) {
the_post();
echo \'otherposts##\';
the_content();
echo \'##endotherposts\';
break;
}
}
或者将代码滚到同一个循环中:if (have_posts()) {
while (have_posts()) {
the_post();
if (0 == $wp_query->current_post) {
echo \'firstpost##\';
else {
echo \'otherposts##\';
}
the_content();
if (0 == $wp_query->current_post) {
echo \'##endfirstpost\';
else {
echo \'##endotherposts\';
}
break;
}
}
抱歉,我是一个PHp初学者,我不知道为什么这个循环对我的标签不起作用。php页面欢迎任何帮助。<?php get_header(); ?> <div class=\"posts\"><!-- BLOG --> <!-- Shapes on sides --> <div class=\"shapes_left\"> </div> <div class=\"shape