Blog Joomla How to Change Pagination Style on Joomla or Sobi2

How to Change Pagination Style on Joomla or Sobi2

I'll share about how to change pagination style on Joomla or Sobi2. I've been troubled of how my website pagination looked. At first, i thought i need to fix the codes at Sobi2 component, but in fact, i need to fix the codes on Joomla Core. FYI, i still use Joomla 1.5. The problem is my website pagination was showing too much links 1 to 10, which looked awful on my web design layout because it turns out to be 2 lines. So in order to make it in 1 line, i need to reduce the pagination links to only showing 1 to 4.

So i just need to edit the "libraries\joomla\html\pagination.php".

Find below scripts...

$displayedPages   = 10;
$this->set( 'pages.start', (floor(($this->get('pages.current') -1) / $displayedPages)) * $displayedPages +1);
if ($this->get('pages.start') + $displayedPages -1 < $this->get('pages.total')) {
$this->set( 'pages.stop', $this->get('pages.start') + $displayedPages -1);
} else {
$this->set( 'pages.stop', $this->get('pages.total'));
}

// If we are viewing all records set the view all flag to true
if ($this->limit == $total) {
$this->_viewall = true;
}

 

Replace it to...

$displayedPages   = 4; // not less than 4 and ONLY round numbers like 10, 12, 14...
$this->set( 'pages.start', $this->get('pages.current') - ($displayedPages / 2));
$this->set( 'pages.stop', $this->get('pages.current') + ($displayedPages / 2));
if ($this->get('pages.start') < 1) {
$this->set( 'pages.start', 1);
if ($this->get('pages.total') >= $displayedPages) {
$this->set( 'pages.stop', $this->get('pages.current') + ($displayedPages - $this->get('pages.current')));
}
else {
$this->set( 'pages.stop', $this->get('pages.total'));
}
}
else if ($this->get('pages.start') >= 1) {
if ($this->get('pages.total') <= $displayedPages) {
$this->set( 'pages.start', 1);
$this->set( 'pages.stop', $this->get('pages.total'));
}
else if ($this->get('pages.total') > $displayedPages) {
if ( ($this->get('pages.total') - $this->get('pages.current')) < ($displayedPages / 2) ){
$this->set( 'pages.start', $this->get('pages.current') - ( ($displayedPages - 1) - ($this->get('pages.total') - $this->get('pages.current'))) );
$this->set( 'pages.stop', $this->get('pages.total'));
}
}
}

 

In my case, i only need to show 4 links, so on "$displayedPages   = 4;" i putted there "4". You can change it to however you want, based on your needs.

You can check the result of my work at garasi24.com.

Source : forum.joomla.org


blog comments powered by Disqus