Move pagination component to function
This commit is contained in:
parent
bbbfbae63b
commit
c5975e5f11
|
@ -53,9 +53,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
|
||||
<?php endwhile; ?>
|
||||
|
||||
<!-- the pagination component -->
|
||||
<?php require get_template_directory() . '/global-templates/pagination.php';understrap_pagination();?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
|
||||
|
@ -64,6 +61,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
|
||||
</main><!-- #main -->
|
||||
|
||||
<!-- The pagination component -->
|
||||
<?php understrap_pagination(); ?>
|
||||
|
||||
</div><!-- #primary -->
|
||||
|
||||
<!-- Do the right sidebar check -->
|
||||
|
|
|
@ -70,9 +70,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
</li>
|
||||
<?php endwhile; ?>
|
||||
|
||||
<!-- the pagination component -->
|
||||
<?php require get_template_directory() . '/global-templates/pagination.php';understrap_pagination();?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
|
||||
|
@ -85,6 +82,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
|
||||
</main><!-- #main -->
|
||||
|
||||
<!-- The pagination component -->
|
||||
<?php understrap_pagination(); ?>
|
||||
|
||||
</div><!-- #primary -->
|
||||
|
||||
<!-- Do the right sidebar check -->
|
||||
|
|
|
@ -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.
|
||||
*/
|
||||
|
|
6
home.php
6
home.php
|
@ -69,6 +69,8 @@ if ( is_front_page() && is_home() ) {
|
|||
<?php if ( 'masonry' === $posts_style ) : ?></div><?php endif; ?>
|
||||
</main><!-- #main -->
|
||||
|
||||
<?php understrap_pagination(); ?>
|
||||
|
||||
</div><!-- #primary -->
|
||||
|
||||
<!-- Do the right sidebar check -->
|
||||
|
@ -79,9 +81,7 @@ if ( is_front_page() && is_home() ) {
|
|||
<?php endif; ?>
|
||||
|
||||
</div><!-- .row -->
|
||||
<?php require get_template_directory() . '/global-templates/pagination.php';
|
||||
understrap_pagination();
|
||||
?>
|
||||
|
||||
</div><!-- Container end -->
|
||||
|
||||
</div><!-- Wrapper end -->
|
||||
|
|
|
@ -0,0 +1,95 @@
|
|||
<?php
|
||||
/**
|
||||
* Pagination layout.
|
||||
*
|
||||
* @package understrap
|
||||
*/
|
||||
|
||||
// Comments form.
|
||||
|
||||
/**
|
||||
* 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() {
|
||||
if ( is_singular() ) {
|
||||
return;
|
||||
}
|
||||
|
||||
global $wp_query;
|
||||
|
||||
/** Stop execution if there's only 1 page */
|
||||
if ( $wp_query->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 '<nav aria-label="Page navigation"><ul class="pagination ">' . "\n";
|
||||
|
||||
/** Link to first page, plus ellipses if necessary */
|
||||
if ( ! in_array( 1, $links ) ) {
|
||||
$class = 1 == $paged ? ' class="active page-item"' : ' class="page-item"';
|
||||
|
||||
printf( '<li %s><a class="page-link" href="%s"><i class="fa fa-step-backward" aria-hidden="true"></i></a></li>' . "\n",
|
||||
$class, esc_url( get_pagenum_link( 1 ) ), '1' );
|
||||
|
||||
/** Previous Post Link */
|
||||
if ( get_previous_posts_link() ) {
|
||||
printf( '<li class="page-item"><span class="page-link">%1$s</span></li> ' . "\n",
|
||||
get_previous_posts_link( '<span aria-hidden="true">«</span><span class="sr-only">Previous page</span>' ) );
|
||||
}
|
||||
|
||||
if ( ! in_array( 2, $links ) ) {
|
||||
echo '<li class="page-item"></li>';
|
||||
}
|
||||
}
|
||||
|
||||
// Link to current page, plus 2 pages in either direction if necessary.
|
||||
sort( $links );
|
||||
foreach ( (array) $links as $link ) {
|
||||
$class = $paged == $link ? ' class="active page-item"' : ' class="page-item"';
|
||||
printf( '<li %s><a href="%s" class="page-link">%s</a></li>' . "\n", $class,
|
||||
esc_url( get_pagenum_link( $link ) ), $link );
|
||||
}
|
||||
|
||||
// Next Post Link.
|
||||
if ( get_next_posts_link() ) {
|
||||
printf( '<li class="page-item"><span class="page-link">%s</span></li>' . "\n",
|
||||
get_next_posts_link( '<span aria-hidden="true">»</span><span class="sr-only">Next page</span>' ) );
|
||||
}
|
||||
|
||||
// Link to last page, plus ellipses if necessary.
|
||||
if ( ! in_array( $max, $links ) ) {
|
||||
if ( ! in_array( $max - 1, $links ) ) {
|
||||
echo '<li class="page-item"></li>' . "\n";
|
||||
}
|
||||
|
||||
$class = $paged == $max ? ' class="active "' : ' class="page-item"';
|
||||
printf( '<li %s><a class="page-link" href="%s" aria-label="Next"><span aria-hidden="true"><i class="fa fa-step-forward" aria-hidden="true"></i></span><span class="sr-only">%s</span></a></li>' . "\n",
|
||||
$class . ' page-item 9', esc_url( get_pagenum_link( esc_html( $max ) ) ), esc_html($max ) );
|
||||
}
|
||||
|
||||
echo '</ul></nav>' . "\n";
|
||||
}
|
||||
|
||||
endif;
|
|
@ -137,89 +137,27 @@ if ( ! function_exists( 'understrap_post_nav' ) ) :
|
|||
return;
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-12">
|
||||
<nav class="navigation post-navigation">
|
||||
<h1 class="sr-only"><?php _e( 'Post navigation', 'understrap' ); ?></h1>
|
||||
<div class="nav-links">
|
||||
<?php
|
||||
|
||||
if ( get_previous_post_link() ) {
|
||||
previous_post_link( '<span class="nav-previous float-xs-left btn btn-sm btn-secondary">%link</span>', _x( '<span class="fa fa-backward"></span> %title', 'Previous post link', 'understrap' ) );
|
||||
previous_post_link( '<button class="nav-previous float-xs-left btn btn-sm btn-secondary">%link</button>', _x( '<i class="fa fa-angle-left" aria-hidden="true"></i>
|
||||
%title', 'Previous post link', 'understrap' ) );
|
||||
}
|
||||
if ( get_next_post_link() ) {
|
||||
next_post_link( '<span class="nav-next float-xs-right btn btn-sm btn-secondary">%link</span>', _x( '%title <span class="fa fa-forward"></span>', 'Next post link', 'understrap' ) );
|
||||
next_post_link( '<button class="nav-next float-xs-right btn btn-sm btn-secondary">%link</button>', _x( '%title <i class="fa fa-angle-right" aria-hidden="true"></i>
|
||||
</span>', 'Next post link', 'understrap' ) );
|
||||
}
|
||||
?>
|
||||
</div><!-- .nav-links -->
|
||||
</nav><!-- .navigation -->
|
||||
</div>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
endif;
|
||||
|
||||
/**
|
||||
* 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_numeric_posts_nav' ) ) :
|
||||
function understrap_numeric_posts_nav() {
|
||||
if( is_singular() )
|
||||
return;
|
||||
global $wp_query;
|
||||
/** Stop execution if there's only 1 page */
|
||||
if( $wp_query->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 '<nav aria-label="Page navigation"><ul class="pagination">' . "\n";
|
||||
/** Previous Post Link */
|
||||
if ( get_previous_posts_link() ) {
|
||||
//printf( '<button class="nav-previous btn btn-ghost btn-raised"><span class="fa fa-backward"></span> %s</button>' . "\n", get_previous_posts_link() );
|
||||
?>
|
||||
<li class="page-item">
|
||||
<?php previous_posts_link( '<span class="fa fa-backward"></span> '. __('Newer posts', 'understrap' )); ?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
/** Link to first page, plus ellipses if necessary */
|
||||
if ( ! in_array( 1, $links ) ) {
|
||||
$class = 1 == $paged ? 'active' : '';
|
||||
printf( '<li class="page-item"><a class="page-link" href="%s">%s</a></span>' . "\n", $class, esc_url( get_pagenum_link( 1 ) ), '1' );
|
||||
if ( ! in_array( 2, $links ) )
|
||||
echo '<li class="page-item">...</li>';
|
||||
}
|
||||
/** Link to current page, plus 2 pages in either direction if necessary */
|
||||
sort( $links );
|
||||
foreach ( (array) $links as $link ) {
|
||||
$class = $paged == $link ? 'active' : '';
|
||||
printf( '<li class="page-item" %s"><a class="page-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $link ) ), $link );
|
||||
}
|
||||
/** Link to last page, plus ellipses if necessary */
|
||||
if ( ! in_array( $max, $links ) ) {
|
||||
if ( ! in_array( $max - 1, $links ) )
|
||||
echo '<li class="page-item">...</li>' . "\n";
|
||||
$class = $paged == $max ? ' active' : '';
|
||||
printf( '<li class="page-item %s"><a class="page-link" href="%s">%s</a></li>' . "\n", $class, esc_url( get_pagenum_link( $max ) ), $max );
|
||||
}
|
||||
/** Next Post Link */
|
||||
if ( get_next_posts_link() ) {
|
||||
//printf( '<button class="nav-next btn btn-ghost btn-raised pull-right">%s <span class="fa fa-forward"></span></button>' . "\n", get_next_posts_link() );
|
||||
?>
|
||||
<li class="page-item">
|
||||
<?php next_posts_link( __('Older posts', 'understrap' ) . ' <span class="fa fa-forward"></span>'); ?>
|
||||
</li>
|
||||
<?php
|
||||
}
|
||||
echo '</ul></nav>' . "\n";
|
||||
}
|
||||
endif;
|
|
@ -52,9 +52,6 @@ if ( is_front_page() && is_home() ) {
|
|||
|
||||
<?php endwhile; ?>
|
||||
|
||||
<!-- the pagination component -->
|
||||
<?php require get_template_directory() . '/global-templates/pagination.php';understrap_pagination();?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
|
||||
|
@ -63,6 +60,9 @@ if ( is_front_page() && is_home() ) {
|
|||
|
||||
</main><!-- #main -->
|
||||
|
||||
<!-- The pagination component -->
|
||||
<?php understrap_pagination(); ?>
|
||||
|
||||
</div><!-- #primary -->
|
||||
|
||||
<!-- Do the right sidebar check -->
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -45,9 +45,6 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
|
||||
<?php endwhile; ?>
|
||||
|
||||
<!-- the pagination component -->
|
||||
<?php require get_template_directory() . '/global-templates/pagination.php';understrap_pagination();?>
|
||||
|
||||
<?php else : ?>
|
||||
|
||||
<?php get_template_part( 'loop-templates/content', 'none' ); ?>
|
||||
|
@ -56,6 +53,9 @@ $sidebar_pos = get_theme_mod( 'understrap_sidebar_position' );
|
|||
|
||||
</main><!-- #main -->
|
||||
|
||||
<!-- The pagination component -->
|
||||
<?php understrap_pagination(); ?>
|
||||
|
||||
</div><!-- #primary -->
|
||||
|
||||
<!-- Do the right sidebar check -->
|
||||
|
|
Reference in New Issue