为什么不能使用核心功能previous_posts_link()
/next_posts_link()
或posts_nav_link()
, 所有这些都已经解释了分类法归档上下文?
编辑:
我想我现在明白你的问题了。您需要分页链接,而不是上一页/下一页链接。
WordPress还具有分页链接的本机功能:paginate_links()
(Codex ref).
以下是我如何在自己的主题中使用此函数:
function oenology_paginate_archive_page_links( $type = \'plain\', $endsize = 1, $midsize = 1 ) {
global $wp_query, $wp_rewrite;
$wp_query->query_vars[\'paged\'] > 1 ? $current = $wp_query->query_vars[\'paged\'] : $current = 1;
// Sanitize input argument values
if ( ! in_array( $type, array( \'plain\', \'list\', \'array\' ) ) ) $type = \'plain\';
$endsize = (int) $endsize;
$midsize = (int) $midsize;
// Setup argument array for paginate_links()
$pagination = array(
\'base\' => @add_query_arg(\'page\',\'%#%\'),
\'format\' => \'\',
\'total\' => $wp_query->max_num_pages,
\'current\' => $current,
\'show_all\' => false,
\'end_size\' => $endsize,
\'mid_size\' => $midsize,
\'type\' => $type,
\'prev_text\' => \'<<\',
\'next_text\' => \'>>\'
);
if( $wp_rewrite->using_permalinks() )
$pagination[\'base\'] = user_trailingslashit( trailingslashit( remove_query_arg( \'s\', get_pagenum_link( 1 ) ) ) . \'page/%#%/\', \'paged\' );
if( !empty($wp_query->query_vars[\'s\']) )
$pagination[\'add_args\'] = array( \'s\' => get_query_var( \'s\' ) );
echo paginate_links( $pagination );
}