Advertisement
rexcoder

WP Pagination

Jan 5th, 2015
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.05 KB | None | 0 0
  1. <?php
  2. //Put this inside a conditional statement------------------------------------
  3. //Resource: http://codex.wordpress.org/Function_Reference/paginate_links
  4. ?>
  5. ------------------------------------------------------------------------------------------------------
  6. <?php
  7. //paste this to where you want to show pagination: rex_coder_paging_nav();
  8. //Paste the following code to functins.php
  9. if ( ! function_exists( 'rex_coder_paging_nav' ) ) :
  10. /**
  11.  * Display navigation to next/previous set of posts when applicable.
  12.  *
  13.  * @return void
  14.  */
  15.  
  16. function rex_coder_paging_nav() {
  17.         // Don't print empty markup if there's only one page.
  18.         if ( $GLOBALS['wp_query']->max_num_pages < 2 ) {
  19.                 return;
  20.         }
  21.  
  22.         $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  23.         $pagenum_link = html_entity_decode( get_pagenum_link() );
  24.         $query_args   = array();
  25.         $url_parts    = explode( '?', $pagenum_link );
  26.  
  27.         if ( isset( $url_parts[1] ) ) {
  28.                 wp_parse_str( $url_parts[1], $query_args );
  29.         }
  30.  
  31.         $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  32.         $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  33.  
  34.         $format  = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  35.         $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  36.  
  37.         // Set up paginated links.
  38.         $links = paginate_links( array(
  39.                 'base'     => $pagenum_link,
  40.                 'format'   => $format,
  41.                 'total'    => $GLOBALS['wp_query']->max_num_pages,
  42.                 'current'  => $paged,
  43.                 'mid_size' => 2,
  44.                 'add_args' => array_map( 'urlencode', $query_args ),
  45.                 'prev_text' => __( '← Previous', 'my-simone' ),
  46.                 'next_text' => __( 'Next →', 'my-simone' ),
  47.                 'type'      => 'list',
  48.         ) );
  49.  
  50.         if ( $links ) :
  51.  
  52.         ?>
  53.         <nav class="navigation paging-navigation" role="navigation">
  54.                 <h1 class="screen-reader-text"><?php _e( 'Posts navigation', 'my-simone' ); ?></h1>
  55.                         <?php echo $links; ?>
  56.         </nav><!-- .navigation -->
  57.         <?php
  58.         endif;
  59. }
  60.    
  61. endif;
  62.  
  63. ?>
  64.  
  65.  
  66. <style>
  67. .paging-navigation ul {
  68.     margin: 0;
  69. }
  70.  
  71. .paging-navigation li { display: inline; }
  72.  
  73. a.page-numbers,
  74. span.page-numbers {
  75.      padding: .3em .7em;
  76.      color: #333;
  77.      color: hsl(0, 0%, 20%);
  78. }
  79.  
  80. a:hover.page-numbers {
  81.     color: #000;
  82.     color: hsl(0, 0%, 0%);
  83. }
  84.  
  85. .paging-navigation .current {
  86.     font-weight: bold;
  87.     color: #000;
  88.     color: hsl(0, 0%, 0%);
  89. }
  90.  
  91. /**********************************************
  92. *content-sidebar.css
  93. ***********************************************/
  94. .paging-navigation {
  95.     padding-top: 1em;
  96.     padding-bottom: 1em;
  97.     margin-bottom: 2em;
  98.     list-style-type: none;
  99.     background: #fff;
  100. }  
  101. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement