Skip to content

Instantly share code, notes, and snippets.

@Kubik-Rubik
Created October 27, 2023 10:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Kubik-Rubik/ef025be01c97703d2d029a4e8577893b to your computer and use it in GitHub Desktop.
Save Kubik-Rubik/ef025be01c97703d2d029a4e8577893b to your computer and use it in GitHub Desktop.
Joomla! - Pagination - Layout override to limit the number of pages
<?php
/**
* @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org>
* @package Joomla.Site
* @subpackage Layout
*
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
use Joomla\CMS\Language\Text;
$list = $displayData['list'];
// Kubik-Rubik Joomla! Extensions - Start
// Change the number of pages shown as required. Possible values: 0 - 9. Default: 5
$pagesShow = 5;
if (count($list['pages']) > $pagesShow) {
$pages = array_values($list['pages']);
$activeKey = 0;
foreach ($pages as $key => $value) {
if ($value['active'] === false) {
$activeKey = $key;
break;
}
}
if (count($list['pages']) - $activeKey < $pagesShow / 2) {
$activeKey = count($list['pages']) - $pagesShow;
} elseif ($activeKey - ($pagesShow / 2) > 0) {
$activeKey -= floor($pagesShow / 2);
} else {
$activeKey = 0;
}
$list['pages'] = array_slice($list['pages'], $activeKey, $pagesShow);
}
// Kubik-Rubik Joomla! Extensions - End
?>
<nav class="pagination__wrapper" aria-label="<?php echo Text::_('JLIB_HTML_PAGINATION'); ?>">
<ul class="pagination ms-0 mb-4">
<?php echo $list['start']['data']; ?>
<?php echo $list['previous']['data']; ?>
<?php foreach ($list['pages'] as $page) : ?>
<?php echo $page['data']; ?>
<?php endforeach; ?>
<?php echo $list['next']['data']; ?>
<?php echo $list['end']['data']; ?>
</ul>
</nav>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment