destoon分页展开函数(列表显示所有分页)
时间:2024-03-17
浏览:168
第一步:扩展函数api/extend.func.php中增加?phpdefined('IN_DESTOON') or exit('Access Denied');function pagesall($total, $p
第一步:扩展函数api/extend.func.php中增加
<?php defined('IN_DESTOON') or exit('Access Denied'); function pagesall($total, $page = 1, $perpage = 20, $demo = '', $step = 3) { global $DT_URL, $DT, $L; if($total <= $perpage) return ''; $items = $total; $total = ceil($total/$perpage); if($page < 1 || $page > $total) $page = 1; if($demo) { $demo_url = str_replace('%7Bdestoon_page%7D', '{destoon_page}', $demo); $home_url = str_replace('{destoon_page}', '1', $demo_url); } else { if(defined('DT_REWRITE') && $DT['rewrite'] && $_SERVER["script_NAME"] && strpos($DT_URL, '?') === false) { $demo_url = $_SERVER["script_NAME"]; $demo_url = str_replace('//', '/', $demo_url);//Fix Nginx $mark = false; if(substr($demo_url, -4) == '.php') { if(strpos($_SERVER['QUERY_STRING'], '.html') === false) { $qstr = ''; if($_SERVER['QUERY_STRING']) { if(substr($_SERVER['QUERY_STRING'], -5) == '.html') { $qstr = '-'.substr($_SERVER['QUERY_STRING'], 0, -5); } else { parse_str($_SERVER['QUERY_STRING'], $qs); foreach($qs as $k=>$v) { $qstr .= '-'.$k.'-'.rawurlencode($v); } } } $demo_url = substr($demo_url, 0, -4).'-htm-page-{destoon_page}'.$qstr.'.html'; } else { $demo_url = substr($demo_url, 0, -4).'-htm-'.$_SERVER['QUERY_STRING']; $mark = true; } } else { $mark = true; } if($mark) { if(strpos($demo_url, '%') === false) $demo_url = rawurlencode($demo_url); $demo_url = str_replace(array('%2F', '%3A'), array('/', ':'), $demo_url); if(strpos($demo_url, '-page-') !== false) { $demo_url = preg_replace("/page-([0-9]+)/", 'page-{destoon_page}', $demo_url); } else { $demo_url = str_replace('.html', '-page-{destoon_page}.html', $demo_url); } } $home_url = str_replace('-page-{destoon_page}', '-page-1', $demo_url); } else { $DT_URL = str_replace('&', '&', $DT_URL); $demo_url = $home_url = preg_replace("/(.*)([&?]page=[0-9]*)(.*)/i", "\\1\\3", $DT_URL); $s = strpos($demo_url, '?') === false ? '?' : '&'; $demo_url = $demo_url.$s.'page={des'.'toon_page}'; if(defined('DT_ADMIN') && strpos($demo_url, 'sum=') === false) $demo_url = str_replace('page=', 'sum='.$items.'&page=', $demo_url); } } $pages = ''; include DT_ROOT.'/api/pages.all.php'; return $pages; } ?>
第二步:api/中创建新文件pages.all.php,代码如下:
<?php defined('IN_DESTOON') or exit('Access Denied'); $_page = $page <= 1 ? $total : ($page - 1); $demo_url = str_replace(array('%7B', '%7D'), array('{', '}'), $demo_url); $url = $_page == 1 ? $home_url : str_replace('{destoon_page}', $_page, $demo_url); for($_page = 1; $_page <= $total; $_page++) { $url = $_page == 1 ? $home_url : str_replace('{destoon_page}', $_page, $demo_url); $pages .= $page == $_page ? '<strong> '.$_page.' </strong> ' : ' <a href="'.$url.'">'.$_page.'</a> '; } ?>第三步:应用新的分页方法,示例代码:
$pages = pagesall($num, $page, $pagesize, $demo_url);效果展示: