Warning: Trying to access array offset on false in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 216
rewind_posts() - 文章循环回倒(重置) - WordPress函数 - WordPress动力
当前浏览:首页 / WordPress函数 / rewind_posts()

rewind_posts()

文章循环回倒(重置)


Warning: Undefined array key -1 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 185

Warning: Undefined array key 2 in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/reference-cat.php on line 186

Warning: Undefined variable $searchand in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 154

Warning: Undefined array key "90bc51819c89f7657afbc48dce2e8b1c" in /www/wwwroot/www.wpdongli.com/wp-content/themes/WPdongli/functions/wp.php on line 223

postsmore...


说明

需要对同一个循环执行多次循环时,使用此函数进行重置。



源码

查看源码 官方文档


更新日志

版本描述
1.5.0开始引入

使用示例

  • 示例1

    基本示例

    // 主循环
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    
    // 回倒循环
    <?php rewind_posts(); ?>
    
    // 新循环
    <?php while (have_posts()) : the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
    
  • 示例2

    从Codex迁移的自定义查询示例

    <?php 
    $args = array( 'posts_per_page' => -1 );
    $my_posts = new WP_Query($args);
    if ($my_posts->have_posts()) : while ($my_posts->have_posts()) : $my_posts->the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; endif; ?>
    
    // rewind
    <?php $my_posts->rewind_posts(); ?>
    
    // new loop
    <?php while ($my_posts->have_posts()) : $my_posts->the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>