Override pagination to show fewer page links

Everything to do with Joomla! 5.x templates and templating.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.
Windows Defender SmartScreen Issues <-- please read this if using Windows 10.
Post Reply
ericuhl
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed May 02, 2018 8:02 pm

Override pagination to show fewer page links

Post by ericuhl » Wed May 08, 2024 8:05 pm

I'm currently developing my own custom template and I've cloned Cassiopeia and began modifying it. My issue is that if there is enough content, the pagination looks like this:
<< < 1 2 3 4 5 6 7 8 9 10 > >>

What I'd like to do is reduce the number of page links so that it looks like this
<< < 1 2 3 4 5 > >>

I found the Joomla Core file that puts the pagination together here:
public_html/library/src/Pagination/Pagination.php

But this is a Joomla Core file and I don't want to alter it, or I'm not sure how to properly override it. If I take Pagination.php and clone it to "public_html/templates/[template_name]/html/" I get a namespace error.

I've also created overrides of the layout files here at:

public_html/templates/[template_name]/html/layouts/joomla/pagination/link.php
public_html/templates/[template_name]/html/layouts/joomla/pagination/links.php
public_html/templates/[template_name]/html/layouts/joomla/pagination/list.php

Can someone help me figure out how to properly override the pagination for Joomla? If there is any other information that I can provide please let me know.

User avatar
carlitorweb
Joomla! Intern
Joomla! Intern
Posts: 68
Joined: Tue May 08, 2018 9:03 pm

Re: Override pagination to show fewer page links

Post by carlitorweb » Wed May 08, 2024 8:24 pm

Unfortunately, is not possible through an override or a param set in the administrator. You can see this value is set hardcode in the Pagination class, line #157

You can change that value to 5 and see the result. I will raise a feature issue in the joomla repo about this, I think is not bad idea set a global configuration param for it
You do not have the required permissions to view the files attached to this post.
The future will be automated, decentralized, and digital.

SharkyKZ
Joomla! Hero
Joomla! Hero
Posts: 2967
Joined: Fri Jul 05, 2013 10:35 am
Location: Parts Unknown

Re: Override pagination to show fewer page links

Post by SharkyKZ » Thu May 09, 2024 5:26 am

Until the option is introduced, you override links.php. Inside this block:

Code: Select all

if (!empty($pages['pages'])) {
Add this:

Code: Select all

$pages['pages'] = array_slice($pages['pages'], 0, 5);

ericuhl
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed May 02, 2018 8:02 pm

Re: Override pagination to show fewer page links

Post by ericuhl » Mon May 13, 2024 8:41 pm

carlitorweb - Thank you for confirming that this is not possible. I would love to have this as a feature in the settings. Right now 10 pages it too many pages to display on mobile views and the pagination folds under itself.

SharkyKZ - I tried following along with your suggestion but it doesn't seem to work? I tried to add the line of code in several places in the links.php file and it doesn't do anything. It also seems like this may be the wrong file because the classes on the <ul> are not right. It looks like the code I need to edit is in the list.php file. I think I need to override lines 23-25, here is that code

<?php foreach ($list['pages'] as $page) : ?>
<?php echo $page['data']; ?>
<?php endforeach; ?>

What I think I'd need to override is the foreach loop so that it only runs a certain amount of times? But I have no idea how to do this.


Post Reply

Return to “Templates for Joomla! 5.x”