Custom pagination to display "current page" in the middle...

Your code modifications and patches you want to share with others.
Locked
sazbaztaz
Joomla! Intern
Joomla! Intern
Posts: 66
Joined: Thu Mar 18, 2010 2:20 pm

Custom pagination to display "current page" in the middle...

Post by sazbaztaz » Sun Sep 05, 2010 3:17 pm

Hello all,

After searching the net I found no topics for setting the "current active page" in the middle of the pagination list so users can ALWAYS jump few pages ahead or back if they want to. I thought someone would be interested so here's the code I changed the core libraries\joomla\html\pagination.php

Find...

Code: Select all

		$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 with...

Code: Select all

		$displayedPages	= 10; // not less than 4 and ONLY round numbers like 10, 12, 14...
		$this->set( 'pages.start', $this->get('pages.current') - (($displayedPages / 2) + 1));
		$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'));
			}
			}
			}
I tested this and it works but I suggest to make a backup of your pagination.php first if you want to give it a try. See the attached image...
You do not have the required permissions to view the files attached to this post.

Hitking
Joomla! Apprentice
Joomla! Apprentice
Posts: 15
Joined: Fri Jun 11, 2010 1:47 pm

Re: Custom pagination to display "current page" in the middl

Post by Hitking » Tue Oct 19, 2010 5:11 pm

Thank you very much for perfect guide

moonleaf
Joomla! Apprentice
Joomla! Apprentice
Posts: 10
Joined: Wed Dec 24, 2008 11:43 pm

Re: Custom pagination to display "current page" in the middl

Post by moonleaf » Fri Jan 28, 2011 5:09 am

Agreed--works great!


Locked

Return to “Core Hacks and Patches”