Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Display navigation to next/previous set of posts when applicable.
- * Replace "theme_name" by your theme name.
- */
- if ( ! function_exists( 'theme_name_paging_nav' ) ) :
- function theme_name_paging_nav() {
- // Don't print empty markup if there's only one page.
- if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
- return;
- }
- $paged = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
- $pagenum_link = html_entity_decode( get_pagenum_link() );
- $query_args = array();
- $url_parts = explode( '?', $pagenum_link );
- if ( isset( $url_parts[1] ) ) {
- wp_parse_str( $url_parts[1], $query_args );
- }
- $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
- $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
- $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
- $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
- // Set up paginated links.
- $links = paginate_links( array(
- 'base' => $pagenum_link,
- 'format' => $format,
- 'total' => $GLOBALS['wp_query']->max_num_pages,
- 'current' => $paged,
- 'mid_size' => 1,
- 'add_args' => array_map( 'urlencode', $query_args ),
- 'prev_text' => __( '← Previous', 'theme_name' ),
- 'next_text' => __( 'Next →', 'theme_name' ),
- ) );
- if ( $links ) :
- ?>
- <nav class="navigation paging-navigation" role="navigation">
- <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'theme_name' ); ?></h1>
- <div class="pagination loop-pagination">
- <?php echo $links; ?>
- </div><!-- .pagination -->
- </nav><!-- .navigation -->
- <?php
- endif;
- }
- endif;
- /*
- * Paste the following code where you want to show page navigation
- */
- theme_name_paging_nav();
- /*
- * Paste the following code at your style.css file
- */
- .paging-navigation {
- margin: 48px 0;
- }
- .paging-navigation .loop-pagination {
- text-align: center;
- margin: 0 auto;
- display: table;
- }
- .paging-navigation .page-numbers {
- display: inline-block;
- font-size: 14px;
- font-weight: 900;
- margin-right: 1px;
- padding: 7px 16px;
- text-transform: uppercase;
- }
- .paging-navigation a {
- background-color: #ffffff;
- border: 1px solid #dddddd;
- line-height: 1.42857;
- position: relative;
- text-decoration: none;
- color: #000;
- }
- .paging-navigation .page-numbers.current {
- background-color: #EEEEEE;
- border: 1px solid #dddddd;
- }
- .paging-navigation a:hover {
- background-color: #EEEEEE;
- color: #000;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement