Hello everyone,
I found good digg like pagination class. It looks very nice and may be used with modxcms. Screenshot attached.
I’ve made some hacks to use it with MODX and use it with my fileshare service
www.sharemania.ru to show user files

.
Here is the simple ’how to’ use it with modx:
1) First download the class and place it under snippets directory. For example dir is : snippets/pagination/pagination.class.php.
How to use it with snippets:
Before show the pagination you must know the parameters:
1) how many items totally in you list.
2) how many items you will put per one page
3) Which http variable will describe current page
//Include paginator Class
include_once $modx->config['base_path'] . 'assets/snippets/pagination/pagination.class.php';
...
$output ='';
// Here is the Mysql call , or function call to calculate total number of items
// replace it with yours
$total_items = getTotalItems();
$items_perpage = 10;
// Variable to analyze - where are we now at ?
$page = intval($_GET['page']);
// Some security tricks
if((!$page) || (is_numeric($page) == false) || $page<=0 || $page > ceil($total_items/$items_perpage) ) {
$page = 1; //default
}
// Calculate offset in table , pages start with 1, offset in MYSql with 0.
$start = ($page-1)*$items_perpage;
// Call Mysql to get portion of items ( sure, you must change query to yours needs )
$table = $modx->getFullTableName( 'yours_table' );
$result = $modx->db->select( 'part1,part2', $table, 'condition statement' ', '',' '.$start.','.$items_perpage.' ');
if( $modx->db->getRecordCount( $result ) >= 1 ) {
while( $row = $modx->db->getRow( $result ) ) {
// Add to output every entry
$output .= $row['part1'].$row['part2'].'<br />' ;
}
} else { $output .= "No Items found"; }
// And finally paginator
$p = new pagination;
$p->items($total_items);
$p->limit($items_perpage);
$p->parameterName("page");
$p->adjacents(2);
$p->currentPage($page);
$p->target("/self_url");
$output .= $p->show();
return $output;
You can also customize paginator with css:
.pagination {
width: auto;
padding: 5px;
}
.pagination .disabled {
border: 1px solid #808080;
background-color: white;
padding: 1px 5px 2px;
margin-right: 1px;
text-decoration: none !important;
color: #808080;
}
.pagination .current {
border: 1px solid black;
background-color: green;
padding: 1px 5px 2px;
margin-right: 1px;
text-decoration: none !important;
color: white;
}
.pagination a, .pagination a:link, .pagination a:visited {
border: 1px solid #green;
padding: 1px 5px 2px;
margin-right: 1px;
text-decoration: none !important;
color: black;
}
.pagination a:hover {
background-color: #green;
color: #000;
}
So, thats all, very shortly. This class has a few additional properties: you can customize next/prev buttons, css classes to use with, etc..
Author homepage is:
http://www.mis-algoritmos.com/2007/05/27/digg-style-pagination-class/?foo=var&page=3
Thanks,
Dmitry