From 33183a34811f4f02fd235490524b71d844bb278a Mon Sep 17 00:00:00 2001 From: 0dp Date: Sat, 24 Mar 2018 14:18:00 +0100 Subject: [PATCH] new pagination --- global-templates/.DS_Store | Bin 0 -> 6148 bytes global-templates/pagination.php | 97 ------------------------- inc/pagination.php | 121 ++++++++++++-------------------- 3 files changed, 43 insertions(+), 175 deletions(-) create mode 100644 global-templates/.DS_Store delete mode 100644 global-templates/pagination.php diff --git a/global-templates/.DS_Store b/global-templates/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..19b11fbf7a5f5be22f5df6c500fad06364e71a70 GIT binary patch literal 6148 zcmeHKJx{|x41I>X|Ept2T#IHKEx zwqBVvrv%o4y(4ER;;BSWm1r@<)9Eh}R|ocvo(_rTL*mVE&5PLES-)5~q;^c53?u{V z3~2958SD9f!e3^v$+wVH$v`sjUm1|m>})pW*TvcT={xnTEga_@DjL_TL7}~N3E+e7 fBl|Y#^F?jO)q%aER#CsD6Z0ZqgrrIaeu05k)c-#> literal 0 HcmV?d00001 diff --git a/global-templates/pagination.php b/global-templates/pagination.php deleted file mode 100644 index e45049a..0000000 --- a/global-templates/pagination.php +++ /dev/null @@ -1,97 +0,0 @@ -max_num_pages <= 1 ) { - return; - } - - $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1; - $max = intval( $wp_query->max_num_pages ); - - /** Add current page to the array */ - if ( $paged >= 1 ) { - $links[] = $paged; - } - - /** Add the pages around the current page to the array */ - if ( $paged >= 3 ) { - $links[] = $paged - 1; - $links[] = $paged - 2; - } - - if ( ( $paged + 2 ) <= $max ) { - $links[] = $paged + 2; - $links[] = $paged + 1; - } - - echo '' . "\n"; -} diff --git a/inc/pagination.php b/inc/pagination.php index cf07258..8874fed 100644 --- a/inc/pagination.php +++ b/inc/pagination.php @@ -5,89 +5,54 @@ * @package understrap */ -/** - * Custom Pagination with numbers - * Credits to http://www.wpbeginner.com/wp-themes/how-to-add-numeric-pagination-in-your-wordpress-theme/ - */ + if ( ! function_exists( 'understrap_pagination' ) ) : + function understrap_pagination($args = [], $class = 'pagination') { -if ( ! function_exists( 'understrap_pagination' ) ) : -function understrap_pagination() { - if ( is_singular() ) { - return; - } + if ($GLOBALS['wp_query']->max_num_pages <= 1) return; - global $wp_query; + $args = wp_parse_args( $args, [ + 'mid_size' => 2, + 'prev_next' => false, + 'prev_text' => __('«', 'understrap'), + 'next_text' => __('»', 'understrap'), + 'screen_reader_text' => __('Posts navigation', 'understrap'), + 'type' => 'array', + 'current' => max( 1, get_query_var('paged') ), + ]); - /** Stop execution if there's only 1 page */ - if ( $wp_query->max_num_pages <= 1 ) { - return; - } + $links = paginate_links($args); + $next_link = get_next_posts_page_link(); + $prev_link = get_previous_posts_page_link(); - $paged = get_query_var( 'paged' ) ? absint( get_query_var( 'paged' ) ) : 1; - $max = intval( $wp_query->max_num_pages ); + ?> - /** Add current page to the array */ - if ( $paged >= 1 ) { - $links[] = $paged; - } + +