From c5975e5f1149ccb74f9f5454a4b39beb534eeb7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Holger=20Ko=CC=88nemann?= Date: Wed, 23 Nov 2016 10:42:53 +0100 Subject: [PATCH] Move pagination component to function --- archive.php | 6 +- author.php | 6 +- functions.php | 5 ++ home.php | 6 +- inc/pagination.php | 95 +++++++++++++++++++++++++++++ inc/template-tags.php | 102 +++++++------------------------- index.php | 6 +- sass/understrap/understrap.scss | 6 +- search.php | 6 +- 9 files changed, 138 insertions(+), 100 deletions(-) create mode 100644 inc/pagination.php diff --git a/archive.php b/archive.php index 6d6897a..33cf20a 100644 --- a/archive.php +++ b/archive.php @@ -53,9 +53,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); - - - @@ -64,6 +61,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); + + + diff --git a/author.php b/author.php index 314b8a4..e177e5f 100644 --- a/author.php +++ b/author.php @@ -70,9 +70,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); - - - @@ -85,6 +82,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); + + + diff --git a/functions.php b/functions.php index c67523c..9776e27 100644 --- a/functions.php +++ b/functions.php @@ -32,6 +32,11 @@ require get_template_directory() . '/inc/enqueue.php'; */ require get_template_directory() . '/inc/template-tags.php'; +/** + * Custom template tags for this theme. + */ +require get_template_directory() . '/inc/pagination.php'; + /** * Custom functions that act independently of the theme templates. */ diff --git a/home.php b/home.php index 5882d5f..d6c26d7 100644 --- a/home.php +++ b/home.php @@ -69,6 +69,8 @@ if ( is_front_page() && is_home() ) { + + @@ -79,9 +81,7 @@ if ( is_front_page() && is_home() ) { - + diff --git a/inc/pagination.php b/inc/pagination.php new file mode 100644 index 0000000..e00f0dc --- /dev/null +++ b/inc/pagination.php @@ -0,0 +1,95 @@ +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"; +} + +endif; \ No newline at end of file diff --git a/inc/template-tags.php b/inc/template-tags.php index 975256c..98a7cbc 100644 --- a/inc/template-tags.php +++ b/inc/template-tags.php @@ -137,89 +137,27 @@ if ( ! function_exists( 'understrap_post_nav' ) ) : return; } ?> - +
+
+ +
+
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"; -} endif; \ No newline at end of file diff --git a/index.php b/index.php index 04c0a6d..2c22121 100644 --- a/index.php +++ b/index.php @@ -52,9 +52,6 @@ if ( is_front_page() && is_home() ) { - - - @@ -63,6 +60,9 @@ if ( is_front_page() && is_home() ) { + + + diff --git a/sass/understrap/understrap.scss b/sass/understrap/understrap.scss index 4a364a8..f4b05cb 100644 --- a/sass/understrap/understrap.scss +++ b/sass/understrap/understrap.scss @@ -132,9 +132,9 @@ a.skip-link { .post-navigation, .paged-navigation { - padding-top: 1rem; - margin-top: 1rem; - border-top: 1px solid $gray-dark; + padding: ($grid-gutter-width-base/2) 0; + margin: $grid-gutter-width-base 0; + border-top: 1px solid $gray-lighter; } // Fixing BS dropdown in a dropdown diff --git a/search.php b/search.php index 5ccb159..19e4659 100644 --- a/search.php +++ b/search.php @@ -45,9 +45,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); - - - @@ -56,6 +53,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' ); + + +