我找到了以下代码:
// Get total number of pages
global $wp_query;
$total = $wp_query->max_num_pages;
// Only paginate if we have more than one page
if ( $total > 1 ) {
// Get the current page
if ( !$current_page = get_query_var(\'paged\') )
$current_page = 1;
// Structure of “format” depends on whether we’re using pretty permalinks
$permalinks = get_option(\'permalink_structure\');
$format = empty( $permalinks ) ? \'&page=%#%\' : \'page/%#%/\';
echo paginate_links(array(
\'base\' => get_pagenum_link(1) . \'%_%\',
\'format\' => $format,
\'current\' => $current_page,
\'total\' => $total,
\'mid_size\' => 2,
\'type\' => \'list\'
));
}
它工作正常,但它会生成分页,如“1,2,3…LASTPAGENUMBER”,我见过生成分页的插件,如“1,2,3…19,20,30…LASTPAGENUMBER”。这可以通过使用paginate\\u links()函数实现吗?
我不想仅仅为了这个小小的调整而添加插件。