PHP控制
/***************************** 分页函数方法开始 *********************************/
function paginationzdy($total, $pageIndex, $pageSize = 15, $url = '', $context = array('before' => 1, 'after' => 1, 'ajaxcallback' => '', 'callbackfuncname' => '')) {
global $_W;
$pdata = array(
'tcount' => 0,
'tpage' => 0,
'cindex' => 0,
'findex' => 0,
'pindex' => 0,
'nindex' => 0,
'lindex' => 0,
'options' => ''
);
if ($context['ajaxcallback']) {
$context['isajax'] = true;
}
if ($context['callbackfuncname']) {
$callbackfunc = $context['callbackfuncname'];
}
$pdata['tcount'] = $total;
$pdata['tpage'] = (empty($pageSize) || $pageSize < 0) ? 1 : ceil($total / $pageSize);
if ($pdata['tpage'] <= 1) {
return '';
}
$cindex = $pageIndex;
$cindex = min($cindex, $pdata['tpage']);
$cindex = max($cindex, 1);
$pdata['cindex'] = $cindex;
$pdata['findex'] = 1;
$pdata['pindex'] = $cindex > 1 ? $cindex - 1 : 1;
$pdata['nindex'] = $cindex < $pdata['tpage'] ? $cindex + 1 : $pdata['tpage'];
$pdata['lindex'] = $pdata['tpage'];
if ($context['isajax']) {
if (empty($url)) {
$url = $_W['script_name'] . '?' . http_build_query($_GET);
}
$pdata['faa'] = 'href="javascript:;" page="' . $pdata['findex'] . '" '. ($callbackfunc ? 'onclick="'.$callbackfunc.'(\'' . $url . '\', \'' . $pdata['findex'] . '\', this);return false;"' : '');
$pdata['paa'] = 'href="javascript:;" page="' . $pdata['pindex'] . '" '. ($callbackfunc ? 'onclick="'.$callbackfunc.'(\'' . $url . '\', \'' . $pdata['pindex'] . '\', this);return false;"' : '');
$pdata['naa'] = 'href="javascript:;" page="' . $pdata['nindex'] . '" '. ($callbackfunc ? 'onclick="'.$callbackfunc.'(\'' . $url . '\', \'' . $pdata['nindex'] . '\', this);return false;"' : '');
$pdata['laa'] = 'href="javascript:;" page="' . $pdata['lindex'] . '" '. ($callbackfunc ? 'onclick="'.$callbackfunc.'(\'' . $url . '\', \'' . $pdata['lindex'] . '\', this);return false;"' : '');
} else {
if ($url) {
$pdata['faa'] = 'href="?' . str_replace('*', $pdata['findex'], $url) . '"';
$pdata['paa'] = 'href="?' . str_replace('*', $pdata['pindex'], $url) . '"';
$pdata['naa'] = 'href="?' . str_replace('*', $pdata['nindex'], $url) . '"';
$pdata['laa'] = 'href="?' . str_replace('*', $pdata['lindex'], $url) . '"';
} else {
$_GET['page'] = $pdata['findex'];
$pdata['faa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
$_GET['page'] = $pdata['pindex'];
$pdata['paa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
$_GET['page'] = $pdata['nindex'];
$pdata['naa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
$_GET['page'] = $pdata['lindex'];
$pdata['laa'] = 'href="' . $_W['script_name'] . '?' . http_build_query($_GET) . '"';
}
}
$html = ' ';
if ($pdata['cindex'] > 1) {
$html .= "<a {$pdata['faa']} class=\"\">首页</a>";
}
if (!$context['before'] && $context['before'] != 0) {
$context['before'] = 1;
}
if (!$context['after'] && $context['after'] != 0) {
$context['after'] = 1;
}
if ($context['after'] != 0 && $context['before'] != 0) {
$range = array();
$range['start'] = max(1, $pdata['cindex'] - $context['before']);
$range['end'] = min($pdata['tpage'], $pdata['cindex'] + $context['after']);
if ($range['end'] - $range['start'] < $context['before'] + $context['after']) {
$range['end'] = min($pdata['tpage'], $range['start'] + $context['before'] + $context['after']);
$range['start'] = max(1, $range['end'] - $context['before'] - $context['after']);
}
for ($i = $range['start']; $i <= $range['end']; $i++) {
if ($context['isajax']) {
$aa = 'href="javascript:;" page="' . $i . '" '. ($callbackfunc ? 'onclick="'.$callbackfunc.'(\'' . $url . '\', \'' . $i . '\', this);return false;"' : '');
} else {
if ($url) {
$aa = 'href="?' . str_replace('*', $i, $url) . '"';
} else {
$_GET['page'] = $i;
$aa = 'href="?' . http_build_query($_GET) . '"';
}
}
$html .= ($i == $pdata['cindex'] ? '<a class="active" href="javascript:;">' . $i . '</a>' : "<a {$aa}>" . $i . '</a>');
}
}
if ($pdata['cindex'] < $pdata['tpage']) {
$html .= "<a {$pdata['laa']} class=\"\">尾页</a> ";
}
$html .= '';
return $html;
}
样式css
<style>
.navigation {
margin:auto auto 10px 10px;
float:left;
}
.wp-paginate {
padding:0;
margin:0;
}
.wp-paginate li {
float:left;
list-style:none;
margin:2px;
padding:0;
}
.wp-paginate a {
margin:0 5px;
line-height:30px;
text-align:center;
text-decoration:none;
border-radius:3px;
-moz-border-radius:3px;
float:left;
min-height:30px;
min-width:34px;
color:#858585; /* 未选中时数字颜色 */
border:2px #e3e3e3 solid; /* 未选中时外圈颜色 */
border-radius:20px;
font-size:12px;
}
.wp-paginate a:hover {
border:2px #858585 solid;
color:#858585;
}
.wp-paginate .title {
color:#555;
margin:0;
margin-right:4px;
font-size:14px;
}
.wp-paginate .gap {
color:#999;
margin:0;
margin-right:4px;
}
.wp-paginate .active {
margin:0 5px;
line-height:30px;
text-align:center;
text-decoration:none;
border-radius:3px;
-moz-border-radius:3px;
float:left;
font-weight:700;
min-height:30px;
min-width:34px;
color:#C72D29; /* 选中时数字颜色 */
border:2px #C72D29 solid; /* 选中时外圈颜色 */
border-radius:20px;
font-size:12px;
}
.wp-paginate .page {
margin:0;
padding:0;
}
.wp-paginate .prev {
}
.wp-paginate .next {
}
</style>
HTML 引用
<!-- 分页部分 -->
<div class="navigation" >
<ol class="wp-paginate">
{$pager}
</ol>
</div>
<!-- 分页部分结束 -->
|