hi everyone i am trying to create my pagination in below format
Go to Page 3 [text-box] Previous 1 2 3 4 5 ….400 Next
and below is my code
if(isset($_REQUEST['limit_start']) && $_REQUEST['limit_start'] > 0) $limit_start = $_REQUEST['limit_start'];
else $limit_start = 0 ;
if(isset($_REQUEST['results_to_show']) ) $results_to_show= $_REQUEST['results_to_show'];
else $results_to_show = 100;
if(($limit_start-$results_to_show)>=0)
$pagination.='<a href="details-inventory.php?limit_start='.($limit_start-$results_to_show).'&&results_to_show='.$results_to_show.'" >Previous</a> | ';
if (isset($_REQUEST['submit']) && $_REQUEST['submit'] != "")$search_limited = 1;
else $search_limited = 0;
global $wpdb;
$sql='SELECT count(*)
FROM `inventory_location` ';
$data= $wpdb->get_results($sql,ARRAY_A);
$row_count= $data[0]['count(*)'];
for($number=(($limit_start/$results_to_show)+1);$number<($row_count/$results_to_show);$number++)//($row_count/$results_to_show);$number++)($limit_start/$results_to_show)+
$pagination.= '<a href="details-inventory.php?limit_start='.($number*$results_to_show).'&&results_to_show='.$results_to_show.'" >'.$number.'</a> | ';
$pagination.= ' <a href="details-inventory.php?limit_start='.($limit_start+$results_to_show).'&&results_to_show='.$results_to_show.'" >Next </a> <br />';
Now the problem is this …..
it show all the numbers from 1 to last page … i want to break it in below style
1 2 3 4 5 ....400
thanx
If you are using WordPress there is an inbuilt function
paginate_links
for pagination.You can view more info on the same here :http://codex.wordpress.org/Function_Reference/paginate_links .
Rather than creating your own, it will be good to use inbuilt function which does the same functionality what you need.
This will help you to suit your needs. You just need to pass the correct arguments.
mid_size
is the argument you need to specify how many page numbers should be shown to either side of current page, but not including current page.UPDATE :
You code can be simplified like below :
Hope this helps 🙂