Prestashop pagination.tpl template tune up

The problem

Many of us noticed that pagination in prestashop works a bit different then you expect it to work.

For example this is pagination for 4 pages:

Why it shows 1,2,3 and where is 4? Just click the second page and:

* them same situation with the last page.

Ok, showing 1 2 3 … 4 wont be great idea but continue showing 1 2 3 is also not the best idea.

 

Why

I don’t know the motivation of creators to do so and can fins only several reasons:

  • pagination output is assigned to the creators of the template which more likely to use the default template code;
  • the main idea was to make pagination compact?!

Nevertheless pagination works correct with large number of pages:

Lets try to solve it!

I saw threads on different forums there people meet this difficulties and sometimes as an alternative solution proposed to increase the number of pages displayed around the selected one. Default value is 2.

To do so you need to edit /classes/FrontController.php and change the value $range=2 to the bigger one.

This method has several disadvantages:

  • It’s not good idea to edit core files
  • It’s not the real solution as you just increase the number of pages around selected one. For  example if you set $range=3 it will be great for 4 pages pagination but you will meet the same problem with 5 pages.

So I find this layout too bad for my shop as users can’t understand the real size of catalog and can’t properly navigate there.

 

Updated pagination code

I made several add-ons to the default code that solved the problem. The part of final pagination.tpl presented below (new code marked yellow bacckground):

$p – current page
$start – first page in default pagination
$end – last page in default pagination
$range – value of “how many pages to show around current one” from FrontController
$pages_nb – last page

Result:

Four pages example:
Seven pages example:
You can leave a response, or trackback from your own site.