title: PHP pagination, displaying only a few page links
body: <p>I am at the tail end of the pagination portion and it was requested to only allow a few page number links at the bottom. Lets say two before and two after the current page if those pages exist.</p>
  
  <pre><code>if($pagination-&gt;total_pages() &gt; 1) {
  if($pagination-&gt;has_previous_page()) {
      echo "&lt;a href=\"results.php?page=";
      echo $pagination-&gt;previous_page();
      echo "\"&gt;&amp;laquo; Previous&lt;/a&gt;";
  }
  
  for($i = 1; $i &lt;= $pagination-&gt;total_pages(); $i++) {
      if($i == $page) {
          echo "&lt;span class=\"current\"&gt;{$i}&lt;/span&gt;";
      } else {
          echo "&lt;a href=\"doc_list.php?page={$i}\"&gt;{$i}&lt;/a&gt;";
      }
  }
  
  if($pagination-&gt;has_next_page()) {
      echo "&lt;a href=\"results.php?page=";
      echo $pagination-&gt;next_page();
      echo "\"&gt;Next &amp;raquo;&lt;/a&gt;";
  }
  }
  </code></pre>
  
  <p>I will be very grateful for any guidance as I have no clue how to resolve this. </p>