在模版页中(非home)中使用Loop要注意wp_query的设置,否则显示出来的posts列表就不对了。

参考代码如下:

<?php

/*

 * Template name: Blog section template

 */

$current_page = (get_query_var('paged')) ? get_query_var('paged') : 1; // get current page number                                                                                    

$args = array(

        'posts_per_page' => get_option('posts_per_page'), // the value from Settings > Reading by default

            'paged'          => $current_page // current page

        );  

query_posts( $args );

 

$wp_query->is_archive = true;

$wp_query->is_home = false;

 

while(have_posts()): the_post();

    ?>  

    <h2><?php the_title() /* post title */ ?></h2>

    <p><?php the_content() /* post content */ ?></p>

    <?php

endwhile;

 

if( function_exists('wp_pagenavi') ) wp_pagenavi(); // WP-PageNavi function