Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Custom Page Pagination
- function wp_custom_pagination($args = [], $class = 'pagination') {
- global $wp_query;
- $mid_size = 1; // default to 1 number each side
- // Check if we are on the first or last page
- $current_page = get_query_var('paged');
- if ( !$current_page || $current_page == $wp_query->max_num_pages ) {
- $mid_size = 1; // 1 numbers before/after the current page
- }
- $args = wp_parse_args( $args, [
- 'mid_size' => $mid_size,
- 'prev_next' => false,
- 'prev_text' => __('Older posts', 'textdomain'),
- 'next_text' => __('Newer posts', 'textdomain'),
- 'screen_reader_text' => __('Posts navigation', 'textdomain'),
- ]);
- $links = paginate_links($args);
- $next_link = get_next_posts_link($args['next_text']);
- $prev_link = get_previous_posts_link($args['prev_text']);
- $template = apply_filters( 'navigation_markup_template', '
- <nav class="navigation %1$s" role="navigation">
- <div class="nav-links">%3$s<div class="page-numbers-container">%4$s</div>%5$s</div>
- </nav>', $args, $class);
- echo sprintf($template, $class, $args['screen_reader_text'], $prev_link, $links, $next_link);
- }
- add_filter('previous_posts_link_attributes', function()
- {
- return 'class="previous"';
- });
- add_filter('next_posts_link_attributes', function()
- {
- return 'class="next"';
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement