Advertisement
sayful

WordPress Page Navigation

Jul 2nd, 2014
290
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Display navigation to next/previous set of posts when applicable.
  4.  * Replace "theme_name" by your theme name.
  5.  */
  6. if ( ! function_exists( 'theme_name_paging_nav' ) ) :
  7.  
  8. function theme_name_paging_nav() {
  9.     // Don't print empty markup if there's only one page.
  10.     if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  11.         return;
  12.     }
  13.  
  14.     $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  15.     $pagenum_link = html_entity_decode( get_pagenum_link() );
  16.     $query_args   = array();
  17.     $url_parts    = explode( '?', $pagenum_link );
  18.  
  19.     if ( isset( $url_parts[1] ) ) {
  20.         wp_parse_str( $url_parts[1], $query_args );
  21.     }
  22.  
  23.     $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  24.     $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  25.  
  26.     $format  = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  27.     $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  28.  
  29.     // Set up paginated links.
  30.     $links = paginate_links( array(
  31.         'base'     => $pagenum_link,
  32.         'format'   => $format,
  33.         'total'    => $GLOBALS['wp_query']->max_num_pages,
  34.         'current'  => $paged,
  35.         'mid_size' => 1,
  36.         'add_args' => array_map( 'urlencode', $query_args ),
  37.         'prev_text' => __( '&larr; Previous', 'theme_name' ),
  38.         'next_text' => __( 'Next &rarr;', 'theme_name' ),
  39.     ) );
  40.  
  41.     if ( $links ) :
  42.  
  43.     ?>
  44.     <nav class="navigation paging-navigation" role="navigation">
  45.         <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'theme_name' ); ?></h1>
  46.         <div class="pagination loop-pagination">
  47.             <?php echo $links; ?>
  48.         </div><!-- .pagination -->
  49.     </nav><!-- .navigation -->
  50.     <?php
  51.     endif;
  52. }
  53. endif;
  54.  
  55. /*
  56. * Paste the following code where you want to show page navigation
  57. */
  58.  theme_name_paging_nav();
  59.  
  60. /*
  61. * Paste the following code at your style.css file
  62. */
  63. .paging-navigation {
  64.     margin: 48px 0;
  65. }
  66.  
  67. .paging-navigation .loop-pagination {
  68.     text-align: center;
  69.     margin: 0 auto;
  70.     display: table;
  71. }
  72.  
  73. .paging-navigation .page-numbers {
  74.     display: inline-block;
  75.     font-size: 14px;
  76.     font-weight: 900;
  77.     margin-right: 1px;
  78.     padding: 7px 16px;
  79.     text-transform: uppercase;
  80. }
  81.  
  82. .paging-navigation a {
  83.     background-color: #ffffff;
  84.    border: 1px solid #dddddd;
  85.    line-height: 1.42857;
  86.     position: relative;
  87.     text-decoration: none;
  88.     color: #000;
  89. }
  90.  
  91. .paging-navigation .page-numbers.current {
  92.     background-color: #EEEEEE;
  93.    border: 1px solid #dddddd;
  94. }
  95.  
  96. .paging-navigation a:hover {
  97.     background-color: #EEEEEE;
  98.    color: #000;
  99. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement