paginate_links()奇怪的网址

时间:2015-09-11 12:05:37

标签: php wordpress url paginate

有人可以告诉我为什么这段代码给我的网址是:“http://localhost/page/1215752191/”而不是像“http://localhost/page/2/”这样的网址?

 this is the code:
function mytheme_paginate() {
    global $paged, $custom_query;
    $big = 99999999999;
    $args = array (
        'base'      => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
        'format'    => '/page/%#%',
        'current'   => max( 1, get_query_var( 'paged' )),
        'total'     => $custom_query->max_num_pages,
        'show_all'  => False,
        'end_size'  => 2,
        'mid_size'  => 2,
        'prev_next' => True,
        'prev_text' =>__( '<' ),
        'next_text' =>__( '>' ),
        'type'      => 'list'
    );

    echo paginate_links( $args );
}

在index.php中我有一个自定义循环,这里的代码如下所示:

  <?php 
$custom_query_args = array( 
    'posts_per_page' => 2,
    'category_name' => 'news', 
    );

// Get current page and append to custom query parameters array
$custom_query_args['paged'] = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1;

// Instantiate custom query
$custom_query = new WP_Query( $custom_query_args );

// Pagination fix
$temp_query = $wp_query;
$wp_query   = NULL;
$wp_query   = $custom_query;

// Output custom query loop
if ( $custom_query->have_posts() ) :
    while ( $custom_query->have_posts() ) :
        $custom_query->the_post();
        the_content();
    endwhile;
endif;
// Reset postdata
wp_reset_postdata();

// Custom query loop pagination
mytheme_paginate();

// Reset main query object
$wp_query = NULL;
$wp_query = $temp_query;
 ?>  

0 个答案:

没有答案