首页 > CMS知识 > 正文

phpcms v9保留中文分页功能并添加英文分页功能的方法

2019 年 4 月 2 日   来源:帮建站   浏览量: 19

1、打开 /phpcms/languages/zh-cn/system.lang.php 文件
找到并复制
$LANG[‘page_item’] = ‘条’;
$LANG[‘previous’] = ‘上一页’;
$LANG[‘next’] = ‘下一页’;

在上边代码的下边粘贴并修改为
$LANG[‘en_page_item’] = ‘ TOTAL’;
$LANG[‘en_previous’] = ‘PRE’;
$LANG[‘en_next’] = ‘NEXT’;

2、打开 /phpcms/libs/functions/global.func.php 文件
找到并复制
function pages($num, $curr_page, $perpage = 20, $urlrule = ”, $array = array(),$setpages = 10) {
if(defined(‘URLRULE’) && $urlrule == ”) {
$urlrule = URLRULE;
$array = $GLOBALS[‘URL_ARRAY’];
} elseif($urlrule == ”) {
$urlrule = url_par(‘page={$page}’);
}
$multipage = ”;
if($num > $perpage) {
$page = $setpages+1;
$offset = ceil($setpages/2-1);
$pages = ceil($num / $perpage);
if (defined(‘IN_ADMIN’) && !defined(‘PAGES’)) define(‘PAGES’, $pages);
$from = $curr_page – $offset;
$to = $curr_page + $offset;
$more = 0;
if($page >= $pages) {
$from = 2;
$to = $pages-1;
} else {
if($from <= 1) {
$to = $page-1;
$from = 2;
}  elseif($to >= $pages) {
$from = $pages-($page-2);
$to = $pages-1;
}
$more = 1;
}
$multipage .= ‘‘.$num.L(‘page_item’).’‘;
if($curr_page>0) {
$multipage .= ‘ ‘.L(‘previous’).’‘;
if($curr_page==1) {
$multipage .= ‘ 1’;
} elseif($curr_page>6 && $more) {
$multipage .= ‘ 1..’;
} else {
$multipage .= ‘ 1‘;
}
}
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= ‘ ‘.$i.’‘;
} else {
$multipage .= ‘ ‘.$i.”;
}
}
if($curr_page<$pages) {
if($curr_page<$pages-5 && $more) {
$multipage .= ‘ ..‘.$pages.’ ‘.L(‘next’).’‘;
} else {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘next’).’‘;
}
} elseif($curr_page==$pages) {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘next’).’‘;
} else {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘next’).’‘;
}
}
return $multipage;
}

在上边代码的下边粘贴并修改为
function en_pages($num, $curr_page, $perpage = 20, $urlrule = ”, $array = array(),$setpages = 10) {
if(defined(‘URLRULE’) && $urlrule == ”) {
$urlrule = URLRULE;
$array = $GLOBALS[‘URL_ARRAY’];
} elseif($urlrule == ”) {
$urlrule = url_par(‘page={$page}’);
}
$multipage = ”;
if($num > $perpage) {
$page = $setpages+1;
$offset = ceil($setpages/2-1);
$pages = ceil($num / $perpage);
if (defined(‘IN_ADMIN’) && !defined(‘PAGES’)) define(‘PAGES’, $pages);
$from = $curr_page – $offset;
$to = $curr_page + $offset;
$more = 0;
if($page >= $pages) {
$from = 2;
$to = $pages-1;
} else {
if($from <= 1) {
$to = $page-1;
$from = 2;
}  elseif($to >= $pages) {
$from = $pages-($page-2);
$to = $pages-1;
}
$more = 1;
}
$multipage .= ‘‘.$num.L(‘en_page_item’).’‘;
if($curr_page>0) {
$multipage .= ‘ ‘.L(‘en_previous’).’‘;
if($curr_page==1) {
$multipage .= ‘ 1’;
} elseif($curr_page>6 && $more) {
$multipage .= ‘ 1..’;
} else {
$multipage .= ‘ 1‘;
}
}
for($i = $from; $i <= $to; $i++) {
if($i != $curr_page) {
$multipage .= ‘ ‘.$i.’‘;
} else {
$multipage .= ‘ ‘.$i.”;
}
}
if($curr_page<$pages) {
if($curr_page<$pages-5 && $more) {
$multipage .= ‘ ..‘.$pages.’ ‘.L(‘en_next’).’‘;
} else {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘en_next’).’‘;
}
} elseif($curr_page==$pages) {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘en_next’).’‘;
} else {
$multipage .= ‘ ‘.$pages.’ ‘.L(‘en_next’).’‘;
}
}
return $multipage;
}

3、打开 /phpcms/libs/classes/template_cache.class.php 文件
找到并复制
$str .= ‘$pages = pages($’.$op.’_total, $page, $pagesize, $urlrule);’;
在上边代码的下边粘贴并修改为
$str .= ‘$en_pages = en_pages($’.$op.’_total, $page, $pagesize, $urlrule);’;
找到并复制
$str .= ‘$r = $get_db->sql_query(“‘.$sql.'”);$s = $get_db->fetch_next();$pages=pages($s[\’count\’], $page, $pagesize, $urlrule);’;
在上边代码的下边粘贴并修改为
$str .= ‘$r = $get_db->sql_query(“‘.$sql.'”);$s = $get_db->fetch_next();$en_pages=en_pages($s[\’count\’], $page, $pagesize, $urlrule);’;

4、模板中调用
中文分页调用方法:{$pages}
英文分页调用方法:{$en_pages}


标签:

首页 在线 手机