你可以做一个简单的str_replace( \'/page/1/\', \'/\', $string )
关于产生的结果paginate_links()
摆脱/page/1/
它显示在第一页链接和上一页链接(当它指向第一页时)上。
下面是一个完整的(经过测试的)示例:
/**
* Numeric pagination via WP core function paginate_links().
* @link http://codex.wordpress.org/Function_Reference/paginate_links
*
* @param array $srgs
*
* @return string HTML for numneric pagination
*/
function wpse_pagination( $args = array() ) {
global $wp_query;
if ( $wp_query->max_num_pages <= 1 ) {
return;
}
$pagination_args = array(
\'base\' => str_replace( 999999999, \'%#%\', esc_url( get_pagenum_link( 999999999 ) ) ),
\'total\' => $wp_query->max_num_pages,
\'current\' => max( 1, get_query_var( \'paged\' ) ),
\'format\' => \'?paged=%#%\',
\'show_all\' => false,
\'type\' => \'array\',
\'end_size\' => 2,
\'mid_size\' => 3,
\'prev_next\' => true,
\'prev_text\' => __( \'« Prev\', \'wpse\' ),
\'next_text\' => __( \'Next »\', \'wpse\' ),
\'add_args\' => false,
\'add_fragment\' => \'\',
// Custom arguments not part of WP core:
\'show_page_position\' => false, // Optionally allows the "Page X of XX" HTML to be displayed.
);
$pagination = paginate_links( array_merge( $pagination_args, $args ) );
// Remove /page/1/ from links.
$pagination = array_map(
function( $string ) {
return str_replace( \'/page/1/\', \'/\', $string );
},
$pagination
);
return implode( \'\', $pagination );
}
Usage:
echo wpse_pagination();