WordPress一個Blog模版頁

在模版頁中(非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


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章