From 5244de420b80d4944bea5161e2deca692924fd7e Mon Sep 17 00:00:00 2001 From: Stef Kariotidis Date: Tue, 22 Nov 2016 13:05:34 +0200 Subject: [PATCH] pagination proposal --- global-templates/pagination.php | 89 +++++++++++++++++++++++++++++++++ home.php | 4 +- 2 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 global-templates/pagination.php diff --git a/global-templates/pagination.php b/global-templates/pagination.php new file mode 100644 index 0000000..4dc38e2 --- /dev/null +++ b/global-templates/pagination.php @@ -0,0 +1,89 @@ +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/home.php b/home.php index e17080f..5882d5f 100644 --- a/home.php +++ b/home.php @@ -79,7 +79,9 @@ if ( is_front_page() && is_home() ) { - +