我想在我的主页上有多个循环,但只显示第一个循环。我的主页如下所示:
<?php
/*
Template Name: Home
*/
get_header(); ?>
<!--Four Columns-->
<hr>
<div id="content" class="twelve columns">
<div class="post-box">
<?php get_template_part(\'loop\', \'land\'); ?>
</div>
</div><!-- End Content row -->
<hr>
<!-- Row for main content area -->
<div id="content" class="twelve columns">
<div class="post-box">
<?php get_template_part(\'loop\', \'home\'); ?>
</div>
</div><!-- End Content row -->
<!--<hr>
<div class="tweleve columns.centered">
<div class="home-title-thoughts">
<h2>Our Thoughts</h2>
</div>
</div>-->
<hr>
<div class="row">
<div class="twelve columns">
<div class="home-quote">
<h3 style="margin-top:0px; margin-bottom:0px;">“Simplicity is the ultimate sophistication.”</h3>
<h4 style="margin-top:0px; margin-bottom:0px;">Leonardo da Vinci</h4>
</div>
</div>
</div>
<?php get_footer(); ?>
这里是环路:
$grids = 3; //Grids per row
global $query_string; //Need this to make pagination work
/*Setting up our custom query (In here we are setting it to show 12 posts per page and eliminate all sticky posts) */
query_posts($query_string . \'&caller_get_posts=1&posts_per_page=9\');
if(have_posts()) : while(have_posts()) : the_post();
?>
<?php
//Show the left hand side column
if($counter == 1) :
?>
<div class="four columns">
<div class="postimage">
<a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail(\'home-thumb\'); ?></a>
</div>
<h3 style="text-align:center;"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3>
<p><?php the_excerpt(); ?></p>
</div>
<div class="clear"></div>
<?php
endif;
?>
<?php
endwhile;
//Pagination can go here if you want it.
endif;
?>
这里是loop home
<?php /* Start loop */ ?>
<?php while (have_posts()) : the_post(); ?>
<!--<h1><?php the_title(); ?></h1>-->
<?php the_content(); ?>
<?php wp_link_pages(array(\'before\' => \'<nav id="page-nav"><p>\' . __(\'Pages:\', \'reverie\'), \'after\' => \'</p></nav>\' )); ?>
<?php endwhile; // End the loop ?>
有没有办法解决这个问题?
最合适的回答,由SO网友:s_ha_dum 整理而成
因为你曾经query_posts
你的loop-land
模板正在删除主查询。Don\'t use query_posts
. 在里面loop-land
改为执行以下操作:
$land = new WP_Query($query_string . \'&caller_get_posts=1&posts_per_page=9\');
if($land->have_posts()) : while($land->have_posts()) : $land->the_post();
发生的事情是
query_posts
覆盖主循环,然后在其上循环。当你到达
have_posts
作为第二个循环的一部分,post计数器已经在末尾。你已经浏览过这些帖子了。