在做wordpress的开发时,需要用到wordpress的分页函数,网上很多人抱怨wordpress没有自带的分页函数,都是自己重新定义的分页函数,今天介绍一个wordpress自带的分页函数paginate_links,函数的参数如下:

<?php $args = array(
    'base'         => '%_%',
    'format'       => '?page=%#%',
    'total'        => 1,
    'current'      => 0,
    'show_all'     => False,
    'end_size'     => 1,
    'mid_size'     => 2,
    'prev_next'    => True,
    'prev_text'    => __(' Previous'),
    'next_text'    => __('Next '),
    'type'         => 'plain',
    'add_args'     => False,
    'add_fragment' => '',
    'before_page_number' => '',
    'after_page_number' => ''
); ?>

具体含义看官方的解释:http://codex.wordpress.org/Function_Reference/paginate_links

   paginate_links函数使用方法一[网友版]:

<?php
global $wp_query;
echo paginate_links(
    array(
        'base' => add_query_arg( 'paged', '%#%' ),
        'format' => '?paged=%#%',
        'total' => $wp_query->max_num_pages,
        'current' => max( 1, get_query_var( 'paged' ) ),
        'show_all' => true,
        'prev_next' => true,
    )
);
?>

   paginate_links函数使用方法二[官方版]:

<?php
global $wp_query;
$big = 999999999; // need an unlikely integer
echo paginate_links(
    array(
    'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
    'format' => '?paged=%#%',
    'current' => max( 1, get_query_var('paged') ),
    'total' => $wp_query->max_num_pages,
        'show_all'=>true,
        'prev_next'=>true
    )
);
?>

其实自己也没有将paginate_links函数看懂,只是按照官方的文档把实现的效果弄出来;有错误请指出,大家互相学习