this post contains code

LightSpeed Webstore Pagination: don’t want pagination to show when there’s only 1 page

I don’t want to see pagination when there’s only 1 page (of products). There’s nothing more annoying than seeing that stupid < 1 > – even more so when there are only 3 products in a particular category.

Here is a solution that uses the Products Per Page in Tools > eCommerce > admin panel > appearance > Products > Products Per Page & the Pagination code in crumbtrail.tpl.php OR product_list.tpl.php. In Brooklyn Template the pagination code is in product_list.tpl.php. I think the other Templates have it placed in crumbtrail.tpl.php.

I used the pagination code I found in Brooklyn product_list.tpl.php and just tweaked it a teeny bit. Brooklyn adds a new code (webstore 2.5 and up) to get rid of the default arrow images which I like because those arrow images filenames are hardcoded in a core file which is a huge pain in the butt. So if your pagination code is in crumbtrail.tpl.php, your Template is probably not based on Brooklyn and you will have to incorporate the new code into crumbtrail.tpl.php in order to get rid of the pagination arrow images:

 if($this->dtrProducts->Paginator) {
	$this->dtrProducts->Paginator->LabelForPrevious = _sp('previous');
	$this->dtrProducts->Paginator->LabelForNext = _sp('next');
}
	$strPaginator = $this->dtrProducts->Paginator->Render(false);

?>

If you get stuck just open Brooklyn, find product_list.tpl.php and you will see what I mean.

By telling TotalItemCount only to show pagination if there are more products in a category than the amount you chose in Products Per Page, you can make it go away when there’s only 1 page. Here the TotalItemCount is told to check if there are more than 8 products on a page:

<?php if ($this->dtrProducts->TotalItemCount > 8) : ?>
<?php if($this->dtrProducts->Paginator) {  echo $strPaginator; } ?>
<?php endif; ?>

When there are more than 8 products, pagination shows up. This pagination thing has bugged me for a while. I was glad to find a solution and I hope it helps someone else. Please do be aware that if the Products Per Page number is changed you have to change the number in the pagination code, too.

In many places in the templates I see conditional statements checking to see if a particular setting has been set in the configuration settings. So I’m sure if I gave it a bit more time I could use a conditional statement to check what the Products Per Page amount is and that way if the setting is ever changed one wouldn’t have to edit the template file as well. But I am pressed for time. I don’t even have time to write this post. Bye!