WordPress一个Blog模版页

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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


以上是关于WordPress一个Blog模版页的主要内容,如果未能解决你的问题,请参考以下文章