Created
October 27, 2023 10:04
-
-
Save Kubik-Rubik/ef025be01c97703d2d029a4e8577893b to your computer and use it in GitHub Desktop.
Joomla! - Pagination - Layout override to limit the number of pages
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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