title: Limited Wordpress Custom Pagination
body: <p>Hi to all I have a funtion to create a numeric pagination for blog posts:</p>
  
  <pre><code>function fb_paging_bar( $args = array() ) {
  
      $defaults = array(
          'range'           =&gt; 4,
          'custom_query'    =&gt; FALSE,
          'previous_string' =&gt; __( 'PREVIOUS', 'themename' ),
          'next_string'     =&gt; __( 'NEXT PAGE', 'themename' ),
          'view_fp'         =&gt; TRUE,
          'view_lp'         =&gt; TRUE,
          'before_output'   =&gt; '&lt;div class="paginator" id="movie_paginator"&gt;',
          'after_output'    =&gt; '&lt;/div&gt;'
      );
  
      $args = wp_parse_args( 
          $args, 
          apply_filters( 'fb_paging_bar_defaults', $defaults )
      );
  
      $args['range'] = (int) $args['range'] - 1;
      if ( !$args['custom_query'] )
          $args['custom_query'] = @$GLOBALS['wp_query'];
      $count = (int) $args['custom_query']-&gt;max_num_pages;
      $page  = intval( get_query_var( 'paged' ) );
      $ceil  = ceil( $args['range'] / 2 );
  
      if ( $count &lt;= 1 )
          return FALSE;
  
      if ( !$page )
          $page = 1;
  
      if ( $count &gt; $args['range'] ) {
          if ( $page &lt;= $args['range'] ) {
              $min = 1;
              $max = $args['range'] + 1;
          } elseif ( $page &gt;= ($count - $ceil) ) {
              $min = $count - $args['range'];
              $max = $count;
          } elseif ( $page &gt;= $args['range'] &amp;&amp; $page &lt; ($count - $ceil) ) {
              $min = $page - $ceil;
              $max = $page + $ceil;
          }
      } else {
          $min = 1;
          $max = $count;
      }
  
      $echo = '';
      $previous = intval($page) - 1;
      $previous = esc_attr( get_pagenum_link($previous) );
      if ( $previous &amp;&amp; (1 != $page) )
          $echo .= '&lt;a class="page page-prev" href="' . $previous . '" title="' . __( 'PREVIOUS', 'themename' ) . '"&gt;' . $args['previous_string'] . '&lt;/a&gt;';
      $firstpage = esc_attr( get_pagenum_link(1) );
  
      if ( $args['view_fp'] &amp;&amp; $firstpage &amp;&amp; (1 != $page) )
          $echo .= '&lt;a class="page" href="' . $firstpage . '"&gt;' . __( '1', 'themename' ) . '&lt;/a&gt;';
  
      if ( !empty($min) &amp;&amp; !empty($max) ) {
          for( $i = $min; $i &lt;= $max; $i++ ) {
              if ($page == $i) {
                  $echo .= '&lt;span class="page page-mobile disabled"&gt;' . str_pad( (int)$i, 1, '0', STR_PAD_LEFT ) . '&lt;/span&gt;';
              } else {
                  $echo .= sprintf( '&lt;a href="%s"&gt;%002d&lt;/a&gt;', esc_attr( get_pagenum_link($i) ), $i );
              }
          }
      }
  
      if ($args['view_lp']) {
          $lastpage = esc_attr( get_pagenum_link($count) );
          if ( $lastpage &amp;&amp; ($count != $page) ) {
              $count = str_pad( (int)$count, 2, '0', STR_PAD_LEFT );
              $echo .= '&lt;span class="page no-page page-mobile disabled"&gt;...&lt;/span&gt;&lt;a class="page" href="' . $lastpage . '"&gt;' . $count . '&lt;/a&gt;';
          }
      }
  
      $next = intval($page) + 1;
      $next = esc_attr( get_pagenum_link($next) );
      if ($next &amp;&amp; ($count != $page) )
          $echo .= '&lt;a class="page page-next" href="' . $next . '" title="' . __( 'NEXT PAGE', 'themename') . '"&gt;' . $args['next_string'] . '&lt;/a&gt;';
  
      if ( isset($echo) )
          echo $args['before_output'] . $echo . $args['after_output'];
  }
  </code></pre>
  
  <p>The result of this code above is like the first image</p>
  
  <p><a href="https://i.stack.imgur.com/ubmOs.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ubmOs.png" alt="enter image description here"></a></p>
  
  <p>But Im trying to find the right way to add more numers because as u see this one shows only first,current and last number</p>
  
  <p>is there any way to make it with more numbers like the second screenshot?</p>
  
  <p><a href="https://i.stack.imgur.com/8AAZF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8AAZF.png" alt="enter image description here"></a></p>