I have a problem with search result page, the pagination i see on my search page is a numeric pagination and I would like to only have a previous and next pagination with a like this url is: www.mywebsite.com/page/{pagenumber}/?s=word below is the code I have and I am having trouble fixing it:
On the function.php I have this
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,
) );
}
}
}
While on my search page for the pagination the code is:
<?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; ?>
you can pass arguments in 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' => ''
);
this are all the arguments please read what each argument use, for your need just pass the 'prev_next' as true,add prev_text and prev_next arguments to format them according to your need.
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 »'),
) );
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.