在之前的教程《Phpcms V9列表分页自定义页码文字方法》中,CMSYOU讲解了如何修改Phpcms语言包做到显示的翻页页码文字改成英文实现英文翻页文字的需求,今天CMSYOU在这里与大家分享Phpcms v9翻页增加下拉跳转的自定义方法。
翻页增加下拉跳转的这个需求也是应一个客户提出的要求而修改的,先看看效果:
Phpcms v9翻页增加下拉跳转具体方法:
修改phpcms/libs/functions/global.func.php中的pages函数为:
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;}// 如果总页数大于1才显示当前页码信息等。if ($pages > 1){$multipage .= '<a>共'.$pages.'页 页次 '.$curr_page.'/'.$pages.' 页</a>';$multipage .= '';$multipage .= '';$multipage .= '<a href="'.pageurl($urlrule, 1, $array).'">首页</a>';$multipage .= '';}if($curr_page>0) {$multipage .= '<a href="'.pageurl($urlrule, $curr_page-1, $array).'" >上一页</a>';if($curr_page==1) {$multipage .= '<span>1</span>';} elseif($curr_page>6 && $more) {$multipage .= '<a href="'.pageurl($urlrule, 1, $array).'">1</a>..';} else {$multipage .= '<a href="'.pageurl($urlrule, 1, $array).'">1</a>';}}for($i = $from; $i <= $to; $i++) {if($i != $curr_page) {$multipage .= '<a href="'.pageurl($urlrule, $i, $array).'">'.$i.'</a>';} else {$multipage .= '<span>'.$i.'</span>';}}if($curr_page<$pages) {if($curr_page<$pages-5 && $more) {$multipage .= '...<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" >下一页</a>';} else {$multipage .= '<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" >下一页</a>';}} elseif($curr_page==$pages) {$multipage .= '<span>'.$pages.'</span> <a href="'.pageurl($urlrule, $curr_page, $array).'" >下一页</a>';} else {$multipage .= '<a href="'.pageurl($urlrule, $pages, $array).'">'.$pages.'</a> <a href="'.pageurl($urlrule, $curr_page+1, $array).'" >下一页</a>';}}$str = http_build_query($_GET);$ppp=explode(page,$str);// 如果总页数大于1才显示“最后一页”。if ($pages > 1){$multipage .= '<a href="'.pageurl($urlrule, $pages, $array).'">尾页</a>';$multipage .= ' 跳转到 <select class="jumpmenu" name="jumpmenu" onchange="javascript:if (this.options[this.selectedIndex].value != \'\')window.open(this.options[this.selectedIndex].value);this.options[0].selected;">';$multipage .= '';for($i=1; $i<=$pages; $i++){$multipage .= '<option value="'.pageurl($urlrule, $i, $array).'">第 '.$i.' 页</option>';}$multipage .= '</select>';$multipage .= '';}return $multipage;}
前台调用翻页的方式还是没变,常规的调用代码就好:
{pc:content action="lists" catid="$catid" num="25" order="id DESC" page="$page"}<ul class="list lh24 f14">{loop $data $r}<li><span class="rt">{date('Y-m-d H:i:s',$r[inputtime])}</span>·<a href="{$r[url]}" target="_blank"{title_style($r[style])}>{$r[title]}</a></li>{if $n%5==0}<li class="bk20 hr"></li>{/if}{/loop}</ul><div class="list-page"><div class="pagenavi">{$pages}</div></div>{/pc}
前台CSS需要对应调整下,具体分享如下:
.list-page{text-align:center}.pagenavi{margin:0;border-radius:0}.pagenavi>a,.pagenavi>span{margin-top:10px;padding:4px 14px;margin-left:6px;color:#777;background-color:#fff;border:1px solid #ddd;display: inline-block;}.pagenavi>a:hover{color:#0192cb}.pagenavi>span,.pagenavi>a:focus,.pagenavi>a:hover{z-index:2;color:#fff;background-color:#0192cb;border-color:#0192cb}.pagenavi>a:first-child{margin-left:0;border-top-left-radius:0;border-bottom-left-radius:0}.pagenavi>a:last-child{border-top-right-radius:0;border-bottom-right-radius:0}.jumpmenu{ height:36px; border:1px solid #ddd; padding:0 5px; margin-top:10px; outline:none;}.jumpmenu option{ line-height:26px;}
以上分享纯属经验,希望对大家有用, 如果对代码有不明白或者出错的地方欢迎点击右侧QQ联系探讨,欢迎联系CMSYOU!
点击加载更多