How can I hide links to pages in the pagination class in Codeigniter?
I am trying to achieve the following effect:
Prev 1 of 4 Next
I tried to set the following option $config
:
$config['num_links'] = 0;
But I am getting the following error:
The number of links should be positive.
My config options are set like:
$config['base_url'] = "/browse/tag/$tid/";
$config['total_rows'] = $num_items;
$config['per_page'] = $max_items;
$config['first_link'] = FALSE;
$config['last_link'] = FALSE;
$config['uri_segment'] = 4;
$config['use_page_numbers'] = TRUE;
$config['display_pages'] = TRUE;
$config['num_links'] = 0; # this doesn't work
$config['prev_link'] = 'Previous';
$config['next_link'] = 'Next';
$config['cur_tag_open'] = '<span>';
$config['cur_tag_close'] = " of $pages</span>";
$config['full_tag_open'] = '<div class="previousnext">';
$config['full_tag_close'] = '</div>';
If I change num_links
to 1, I obviously get:
Prev 1 2 of 4 3 Next
And if I turn off display_pages
, I get:
Prev Next
At this point, I would like to avoid modifying the kernel code.
source to share
If you find it convenient to specify the number of exitst links in the HTML but not display, you can simply hide them with CSS.
Use $config['num_tag_open']
to define an open tag with a class, for example:
$config['num_tag_open'] = '<div class="hidden">';
And then just add CSS:
.hidden { display: none; }
source to share
You need to extend the pagination class by creating a MY_Pagination.php
in the directory application/libraries
and use that to override the function create_links()
that echoes the page list.
MY_Pagination.php
class MY_Pagination extends CI_Pagination{
public function __construct(){
parent::__construct();
}
public function create_links(){
//copy and paste the logic from system/libraries/Pagination.php
//but reimplement lines ~258-296 (CI 2.1.3)
}
}
By introducing changes to the application catalog and extending the kernel, you are protecting yourself from future kernel updates (for example, from 2.1.3 to 3.0).
source to share