Advertisement
Guest User

The Core pagination

a guest
Jul 19th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.76 KB | None | 0 0
  1. function the_core_paging_navigation( $wp_query = null ) {
  2.         if ( ! $wp_query ) {
  3.             $wp_query = $GLOBALS['wp_query'];
  4.         }
  5.  
  6.         // Don't print empty markup if there's only one page.
  7.         if ( $wp_query->max_num_pages < 2 ) {
  8.             return;
  9.         }
  10.  
  11.         $paged        = get_query_var( 'paged' ) ? intval( get_query_var( 'paged' ) ) : 1;
  12.         $pagenum_link = html_entity_decode( get_pagenum_link() );
  13.         $query_args   = array();
  14.         $url_parts    = explode( '?', $pagenum_link );
  15.  
  16.         if ( isset( $url_parts[1] ) ) {
  17.             wp_parse_str( $url_parts[1], $query_args );
  18.         }
  19.  
  20.         $pagenum_link = remove_query_arg( array_keys( $query_args ), $pagenum_link );
  21.         $pagenum_link = trailingslashit( $pagenum_link ) . '%_%';
  22.  
  23.         $format = $GLOBALS['wp_rewrite']->using_index_permalinks() && ! strpos( $pagenum_link, 'index.php' ) ? 'index.php/' : '';
  24.         $format .= $GLOBALS['wp_rewrite']->using_permalinks() ? user_trailingslashit( 'page/%#%', 'paged' ) : '?paged=%#%';
  25.  
  26.         $the_core_pagination_type = function_exists('fw_get_db_settings_option') ? fw_get_db_settings_option('blog_pagination', 'paging-navigation-type-1') : 'paging-navigation-type-1';
  27.         if( $the_core_pagination_type == 'paging-navigation-type-2' ) {
  28.             $prev_text = esc_html__( 'Prev Page', 'the-core' );
  29.             $next_text = esc_html__( 'Next Page', 'the-core' );
  30.             $prev_icon = '<i>&larr;</i>';
  31.             $next_icon = '<i>&rarr;</i>';
  32.         }
  33.         else {
  34.             $prev_text = esc_html__( 'Newer', 'the-core' );
  35.             $next_text = esc_html__( 'Older', 'the-core' );
  36.             $prev_icon = '<i class="fa fa-angle-left"></i>';
  37.             $next_icon = '<i class="fa fa-angle-right"></i>';
  38.         }
  39.  
  40.         // Set up paginated links.
  41.         $links = paginate_links( array(
  42.             'base'      => $pagenum_link,
  43.             'format'    => $format,
  44.             'total'     => $wp_query->max_num_pages,
  45.             'current'   => $paged,
  46.             'mid_size'  => 1,
  47.             'type'      => 'array',
  48.             'add_args'  => array_map( 'urlencode', $query_args ),
  49.             'prev_text' => $prev_icon.'<strong>' . $prev_text . '</strong>',
  50.             'next_text' => '<strong>' . $next_text . '</strong>'.$next_icon,
  51.         ) );
  52.  
  53.         if ( $links ) : ?>
  54.             <nav class="navigation paging-navigation <?php echo esc_attr($the_core_pagination_type); ?>" role="navigation">
  55.                 <div class="pagination loop-pagination">
  56.                     <?php
  57.                     $next = get_next_posts_link();
  58.                     $prev = get_previous_posts_link();
  59.                     if ( empty( $prev ) ) {
  60.                         echo '<a href="javascript:void(0)" class="prev page-numbers disabled">'.$prev_icon.'<strong>' . $prev_text . '</strong></a>';
  61.                         $begin_for = 0;
  62.                     }
  63.                     else {
  64.                         $begin_for = 1;
  65.                     }
  66.  
  67.                     if ( empty( $next ) ) {
  68.                         $end_for = count($links) - 1;
  69.                     }
  70.                     else {
  71.                         $end_for = count($links) - 2;
  72.                     }
  73.  
  74.                     // parse link in foreach for make a wrap only for numbers
  75.                     foreach( $links as $key => $value ) {
  76.                         if( $key == $begin_for ) {
  77.                             echo '<div class="before-hr"></div>';
  78.                             echo '<div class="pagination-numbers-wrap">';
  79.                         }
  80.                         echo ($value);
  81.                         if( $key == $end_for ) {
  82.                             echo '</div>';
  83.                             echo '<div class="after-hr"></div>';
  84.                         }
  85.                     }
  86.  
  87.                     if ( empty( $next ) ) {
  88.                         echo '<a href="javascript:void(0)" class="next page-numbers disabled"><strong>' . $next_text . '</strong>'.$next_icon.'</a>';
  89.                     }
  90.                     ?>
  91.                 </div><!-- .pagination -->
  92.             </nav><!-- .navigation -->
  93.         <?php endif;
  94.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement