PHP pagination Class [ more advanced ]

A more advanced pagination class.
Css classes / Text links are editable.
PHP >5 ONLY!

Usage

Just copy into a php page for debug.
Enjoy !








Example Pagination Class



/* Example stylesheet with default classes */

a{
color:#2786C2;
font-size:14px;
font-weight:bold;

}

div.pages {
width:900px;
margin:0 auto;
margin-top:15px;
margin-bottom:20px;
}

.first-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:20px;

}

.next-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:20px;

}



.prev-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:20px;

}

.numbers-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:10px;

}

.current-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:10px;


}

.last-page{
float:left;
padding:5px 10px 5px 10px;

margin-right:10px;

}

/* clear floats from above */
.clear { clear:both;}

/*
some colors to try out
*/
.blue { color:#2786C2; }
.black { color:#2C2C2C; }
.red { color:#A60000; }
.grey-light { color:#F4F4EE; }
.grey { color:#888884; }
.green { color:#97BB1B; }
.grey_menu { color:#E7E7DE; }
.white { color:#FFFFFF; }

.bg_blue { background-color:#2786C2; }
.bg_black { background-color:#2C2C2C; }
.bg_red { background-color:#A60000; }
.bg_grey-light { background-color:#F4F4EE; }
.bg_grey { background-color:#888884; }
.bg_green { background-color:#97BB1B; }
.bg_grey_menu { background-color:#E7E7DE; }
.bg_white { background-color:#FFFFFF; }

 

Comments

Posted on 13.03.2011 17:13 by paolo_mulder

// usage

// Unqiue page elements
$pag->notice(' Unqiue elements ');

?>
<?=$pag->renderFirst();?>


<?=$pag->renderPrev();?>


<?=$pag->renderNumbers();?>


<?=$pag->renderNext();?>


<?=$pag->renderLast();?>



<?php
// Full pagination in one function
$pag->notice(' Full pagination function ');
?>

<?=$pag->renderPageSet();?>





<?php
/*
Customize full Pageset
$prefix = start wrapper tag
$suffix = end wrapper tag
*/
$pag->notice(' Full pagination function costumized ');

$prefix ='';
$suffix ='';

/*
show numbers ? default=true
*/
$numbers =false;

/*
Show First/Last ? default =true

*/

$first_last=false;

// Render customized Pageset.
echo $pag->renderPageSet( $prefix , $suffix , $numbers , $first_last );


?>



<?php
// Extra vars in url ? not a problem.
$pag->notice(' Extra vars in url ? no problem : Example ');
?>

Posted on 13.03.2011 17:13 by paolo_mulder

OK the usage just stripped every bit of php code.


/*
Example Pagination Class


#Needed vars :

setPage = get current page indication from $_GET
setTotalItems = Total number of rows or items.

*/

#load class.
$path ='';
require_once($path.'pagination.class.php');
$pag =new Pagination( true ); // true = debug ;

$pag->setPage( ($_GET['p']) ? $_GET['p']:1 );
$pag->setTotalItems ( 500 );
$pag->setLimit ( 10 ); #number of items per page ( default = 20 )

/*
Customizing Pagination:
remove # comment to see the effect.
*/

// Changing number of items/rows per page.
// Default = 20
#$pag->setLimit ( 25 );


// Changing page tag for the GET var.
// Default : p=
#$pag->setPageTag( 'page=' );
#$pag->setPage( ($_GET['page']) ? $_GET['page']:1 );

// Changing the number of links (numbers) on page
// Default = 10
#$pag->setLinksOnPage ( 15 );


// Changing css classes
// add a css class below ( stylesheet) and try it out.
// Multiple classes can be applied like shown in the example below.
// Each element can have a different class.
#$pag->setClassPrevPage('prev-page bg_grey-light');
#$pag->setClassNextPage('next-page bg_grey-light');
#$pag->setClassNumbers('numbers-page bg_grey-light');
#$pag->setClassCurrentPage('current-page bg_grey-light green');
#$pag->setClassLastPage('current-page bg_grey-light green');
#$pag->setClassFirstPage('current-page bg_grey-light green');

// Changing text of links
#$pag->setTxtPrevPage('Vorige');
#$pag->setTxtNextPage('Volgende');
#$pag->setTxtCurrentPage("[current] van [last] pagina's");
#$pag->setTxtLastPage('Laatste');
#$pag->setTxtFirstPage('Eerste');


// Redering full pagination also can be customized.
// See end of page.