2

我有 2 个循环,一个用于粘性博客帖子(每页限制为 3 个),一个用于其余帖子。我想每页显示 3 个置顶帖子 + 5 个其他帖子。每页仅显示 5 个其他帖子不起作用。这是他们的循环:

    $loop2query = new WP_Query('ignore_sticky_posts=1'.'showposts=5'.'&paged='.$paged);

  // START 2ND LOOP.
  if ($loop2query->have_posts()) : while ($loop2query->have_posts()) : $loop2query->the_post();
  // Show all posts except the 3 posts in the 1st loop.
  if(in_array($post->ID, $do_not_duplicate)) continue; ?>

  <div class="blogpost">
    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    <p>Written on <?php the_time('m/d/Y') ?>. Filed under <?php the_category(', '); ?>.</p>
  </div>

  <?php the_excerpt();
  endwhile; endif; // END 2ND LOOP. ?>

我认为'showposts=5'.'&paged='.$paged必须是限制每页帖子的正确方法,但我注意到我是否在我的查询中正确使用了。

4

1 回答 1

0

我使用此代码来限制我的类别和每页的帖子数量,试试看:

<?php
$cat = 1;
$showposts = 5; // -1 shows all posts
$do_not_show_stickies = 1; // 0 to show stickies
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
$args=array(
    'category__in' => $cat,
    'showposts' => $showposts,
    'caller_get_posts' => $do_not_show_stickies,
    'paged' => $paged
   );
$my_query = new WP_Query($args); ?>
<?php query_posts($args); if( have_posts() ) :?>
<?php while ( have_posts() ) : the_post(); ?>

<!-- put title and content tags here -->

<?php endwhile;endif; ?>
于 2012-11-04T16:03:30.677 回答