wordpress分页第一页没有数字与自定义参数

问题描述 投票:0回答:1

我正在尝试使用WordPress分页。但是,当我点击第一页时,它总是在页面上重定向它自己,但在这里它重定向页码

function pagination_bar( $custom_query ) {
    $total_pages  = $custom_query->max_num_pages;
    $current_page = isset( $_GET['page_num'] ) ? abs( (int) $_GET['page_num'] ) : 1;
   if ( $total_pages > 1 ) {
      echo '<strong>Page ' . $current_page . ' of ' . $total_pages . '</strong>&nbsp;&nbsp; &nbsp;&nbsp;';
      echo paginate_links( array(
        'base'      => add_query_arg( 'page_num', '%#%' ),
        'format'    => '?page_num=%#%',
        'prev_text' => false,
        'next_text' => false,
        'current'   => $current_page,
        'total'     => $total_pages,
    ) );
  }}

我已经在页面后传递自定义page_num参数。

php wordpress pagination
1个回答
0
投票

试试这个,

add_filter( 'get_pagenum_link', 'wpse_78546_pagenum_link' );

function wpse_78546_pagenum_link( $link )
{
    return preg_replace( '~/page/(\d+)/?~', '?page_num=\1', $link );
}

或者你也可以使用这个插件。 Custom Pagination Permalinks

希望这会对你有所帮助。

欲获得更多信息,

© www.soinside.com 2019 - 2024. All rights reserved.