注:动态下才可用
列表模板调用: echo my_ShowListPage();
自定义分页函数: function my_ShowListPage(){
// 全局 global $empire,$dbtbpre,$fun_r;//引入全局变量
// 当前栏目 $categoryId = $GLOBALS['navclassid']; // 当前栏目 ID $modid = $GLOBALS['class_r'][$categoryId]['modid']; // 当前栏目模型 ID $tableName = $GLOBALS['emod_r'][$modid]['tbname']; // 当前模型对应表名
// 查询记录总数 $query = "SELECT COUNT(*) AS total FROM {$dbtbpre}ecms_{$tableName} WHERE classid = {$categoryId}"; $result = $empire->fetch1($query); $num = (int)$result['total']; // 总条数
// 分页配置 $pagenum = 10; // 每页显示条数 $totalpages = max(1, ceil($num / $pagenum)); // 总页数
$_SESSION['myshowpage']=1; if($_SESSION['myshowpage']>$totalpages) { $_SESSION['myshowpage']=1; } $_SESSION['myshowpage']=$_SESSION['myshowpage']+($num-$pagenum); $page = $_SESSION['myshowpage'];
echo "<br>"; echo $page; echo "<br>";
$dolink = "index"; // 链接模板 $dotype = ".html"; // 链接后缀 $lencord = 5; // 页码导航长度
/// 分页链接生成 $pagelink = "";
// 首页 $pagelink .= $page > 1 ? "<a href='{$dolink}{$dotype}'>{$fun_r['startpage']}</a> " : "<span>{$fun_r['startpage']}</span> ";
// 上一页 if ($page >= 1) { $prevpage = $page - 1; $prevlink = $prevpage == 1 ? "{$dolink}{$dotype}" : "{$dolink}_{$prevpage}{$dotype}"; $pagelink .= "<a href='{$prevlink}'>{$fun_r['pripage']}</a> "; } else { $pagelink .= "<span>{$fun_r['pripage']}</span> "; }
// 中间页 $start = max(1, $page - intval($lencord / 2)); $end = min($totalpages, $start + $lencord - 1);
for ($i = $start; $i <= $end; $i++) { if ($i == $page) { $pagelink .= "<strong>{$i}</strong> "; } else { $link = $i == 1 ? "{$dolink}{$dotype}" : "{$dolink}_{$i}{$dotype}"; $pagelink .= "<a href='{$link}'>{$i}</a> "; } }
// 下一页 if ($page < $totalpages) { $nextpage = $page + 1; $nextlink = "{$dolink}_{$nextpage}{$dotype}"; $pagelink .= "<a href='{$nextlink}'>{$fun_r['nextpage']}</a> "; } else { $pagelink .= "<span>{$fun_r['nextpage']}</span> "; }
// 尾页 if ($page < $totalpages) { $lastlink = "{$dolink}_{$totalpages}{$dotype}"; $pagelink .= "<a href='{$lastlink}'>{$fun_r['lastpage']}</a>"; } else { $pagelink .= "<span>{$fun_r['lastpage']}</span>"; }
// 下拉 $options = "<select name='select' onchange=\"self.location.href=this.options[this.selectedIndex].value\">"; for ($i = 1; $i <= $totalpages; $i++) { $link = $i == 1 ? "{$dolink}{$dotype}" : "{$dolink}_{$i}{$dotype}"; $selected = $i == $page ? " selected" : ""; $options .= "<option value='{$link}'{$selected}>{$fun_r['gotos']}{$i}{$fun_r['gotol']}</option>"; } $options .= "</select>";
// 输出 echo $pagelink . " " . $options; echo "<br>"; echo "totalpages:" . $totalpages;
}
|