Wordpress主题的自定义分页

时间:2016-11-05 08:29:21

标签: php wordpress pagination wordpress-theming

我的搜索结果页面有问题,我在搜索页面上看到的分页是一个数字分页,我想只有一个像以前一样的上一个和下一个分页的网址是:www.mywebsite.com/page / {pagenumber} /?s =下面的单词是我的代码,我无法修复它:

在function.php上我有这个

rendering the pagination links
-------------------------------------
function thrive_pagination() {
    global $wp_query;

    $total_pages = $wp_query->max_num_pages;

    if ( $total_pages > 1 ) {

        $current_page = max( 1, get_query_var( 'paged' ) );

        if ( ! is_search() ) {
            echo paginate_links( array(
                'base'    => trim( get_pagenum_link( 1 ), "/" ) . '/%_%',
                'current' => $current_page,
                'total'   => $total_pages,
            ) );
        } else {
            echo paginate_links( array(
                'base'    => get_pagenum_link( 1 ) . '%_%',
                'format'  => ( ( get_option( 'permalink_structure' ) && ! $wp_query->is_search ) || ( is_home() && get_option( 'show_on_front' ) !== 'page' && ! get_option( 'page_on_front' ) ) ) ? '?paged=%#%' : '&paged=%#%',
                // %#% will be replaced with page number
                'current' => $current_page,
                'total'   => $total_pages,
            ) );
        }
    }
}

在我的搜索页面上,代码为:

<?php $next_page_link = get_next_posts_link();
$prev_page_link = get_previous_posts_link(); ?>

                <ul class="entry-nav">
                <?php if ( $next_page_link || $prev_page_link && ( $next_page_link != "" || $prev_page_link != "" ) ): ?>
                    <?php if ( strpos( $options['blog_layout'], 'masonry' ) === false ): ?>
                        <li class="button next"><?php thrive_pagination(); ?></li>
                        </ul>
                    <?php endif; ?>
                <?php endif; ?>

1 个答案:

答案 0 :(得分:2)

您可以在paginate_links

中传递参数
 $args = array(
    'base'               => '%_%',
    'format'             => '?paged=%#%',
    'total'              => 1,
    'current'            => 0,
    'show_all'           => false,
    'end_size'           => 1,
    'mid_size'           => 2,
    'prev_next'          => true,
    'prev_text'          => __('« Previous'),
    'next_text'          => __('Next »'),
    'type'               => 'plain',
    'add_args'           => false,
    'add_fragment'       => '',
    'before_page_number' => '',
    'after_page_number'  => ''
);

这是所有参数请阅读每个参数使用的内容,因为您的需要只需传递&#39; prev_next&#39;如果为true,请添加prev_text和prev_next参数以根据需要对其进行格式化。

echo paginate_links( array(
                'base'    => get_pagenum_link( 1 ) . '%_%',
                'format'  => ( ( get_option( 'permalink_structure' ) && ! $wp_query->is_search ) || ( is_home() && get_option( 'show_on_front' ) !== 'page' && ! get_option( 'page_on_front' ) ) ) ? '?paged=%#%' : '&paged=%#%',
                // %#% will be replaced with page number
                'current' => $current_page,
                'total'   => $total_pages,
                'prev_next'=>true,
                'prev_text'=> __('« Previous'),
                'next_text'=> __('Next »'),
            ) );