自定义分页代码不起作用

时间:2013-01-01 作者:strange man

我正在使用下面的代码分页。然而,它不起作用。它很好地显示了所有的页码,但当我单击一个页码时,总是显示第一页。

global $wp_query;  
$total_pages = $wp_query->max_num_pages;  
if ( $total_pages > 1 ) {  
    $current_page = max( 1, get_query_var( \'paged\' ) );  
    echo paginate_links( array(  
        \'base\' => get_pagenum_link( 1 ) . \'%_%\',  
        \'format\' => \'/page/%#%\',  
        \'current\' => $current_page,  
        \'total\' => $total_pages,  
    ) );  
}
我的永久链接设置设置为:

本地主机/我的博客/示例帖子/

和查询帖子:

$args=数组(\'post\\u type\'=>\'post\',\'posts\\u per\\u page\'=>2);

如果我将格式更改为

“/页=%\\;%”

它给我提供了404错误。

任何人请告诉我下一步要做什么来完成这个分页。

1 个回复
最合适的回答,由SO网友:Arvind Pal 整理而成
check below code for pagination.

global $paged;
$temp = $wp_query;
$wp_query = null;

$wp_query = new WP_Query( array(\'post_type\' => \'post\',\'posts_per_page\' => 2, \'paged\' => $paged ) ); 
while (have_posts()) : the_post(); 
// Your post content.
endwhile;
echo paginate_links( $args );
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,
    \'prev_text\'    => __(\'Previous\'),
\'next_text\'    => __(\'Next\')
) );
/* Code Ends

Check this code and let me know.
结束

相关推荐

Pagination on custom query

我正在使用以下代码query_posts 要组合自定义搜索,请执行以下操作:$args = array( \'post_type\' => \'species\', \'meta_query\' => $meta_query, \'tax_query\' => $tax_query ); $meta_query 由以下几段代码组成:if (!empty($_POST[\"s_aquarium_H\"])) {