网站栏目页及列表页要实现的效果如下: 2、列表页不限制最大页数,有多少页就列出多少页。 要实现这个效果,需要改动的文件有3个,文件及改动内容如下:
复制代码
代码如下:
/*文件:/include/global.func.php函数:get*//*为 get 函数添加一个参数ismaxpage 就是所添加的参数,用于判断是否启用“列表页最大页数”这个参数而插入代码的部分是为了改变total的值,即记录集总数*/function get($sql, $rows = 0, $page = 0, $dbname = '', $dbsource = '', $urlrule = '', $distinct_field = '', $catid = 0, $ismaxpage = 0) {...if($dbname || $dbsource){$r = $db->get_one("SELECT COUNT(*) AS `count` ".stristr($sql, 'from'));$total = $r['count'];}elseif($distinct_field){$total = cache_count("SELECT COUNT(distinct $distinct_field) AS `count` ".stristr($sql, 'from'));}else{$total = cache_count("SELECT COUNT(*) AS `count` ".stristr($sql, 'from'));}/* 插入以下代码 开始 */global $Phpcms;if ($ismaxpage) {$total = min($total, $PHPCMS['maxpage']*$rows);}/* 插入以上代码 结束 */$pages = pages($total, $page, $rows, $urlrule, '', $catid);...}
复制代码
代码如下:
/*文件:/include/template.func.php函数:get_parse*//*前台 get 标签最后是转换成 get 函数,以下是处理 get 标签的函数因为 get 函数增加了一个参数 $ismaxpage,所以这里也需要做相应修改以下是修改后的部分代码*/function get_parse($str){...extract($r);if(!isset($dbsource)) $dbsource = '';if(!isset($dbname)) $dbname = '';if(!isset($sql)) $sql = '';if(!isset($rows)) $rows = 0;if(!isset($urlrule)) $urlrule = '';if(!isset($catid)) $catid = 0;if(!isset($distinctfield)) $distinctfield = '';if(!isset($return) || !preg_match("/^\w+$/i", $return)) $return = 'r';if(!isset($ismaxpage)) $ismaxpage = 0; /* 增加部分 */if(isset($page)){/* 修改部分,增加了 $ismaxpage 这个参数,仔细看 */$str = "Data=\$ARRAY['data'];\$total=\$ARRAY['total'];\$count=\$ARRAY['count'];\$pages=\$ARRAY['pages'];unset(\$ARRAY);foreach(\$DATA AS \$n=>\${$return}){\$n++;?>";}...}
复制代码
代码如下:
/*文件:/admin/html.inc.php*//* 找到以下代码 */if($CATEGORY[$catid]['child']){$pages = 1;$html->category($catid);}else{$offset = $pagesize*($page-1);if($page == 1){$CONtents = cache_count("SELECT COUNT(*) AS `count` FROM `".DB_PRE."content` WHERE catid=$catid AND status=99");$total = ceil($contents/$PHPCMS['pagesize']);$pages = ceil($total/$pagesize);}$max = min($offset+$pagesize, $total);for($i=$offset; $i<=$max; $i++){$html->category($catid, $i);}}/* 然后把上面的代码替换成以下的代码 */$offset = $pagesize*($page-1);if($page == 1){$condition=get_sql_catid($catid);$contents = cache_count("SELECT COUNT(*) AS `count` FROM `".DB_PRE."content` WHERE status=99 $condition");$total = ceil($contents/$PHPCMS['pagesize'])+1;/* 以下这行代码确保了生成的栏目及列表页的数量是正确的,该生成多少页就是多少页 */$total = $CATEGORY[$catid]['child'] ? min($total, $PHPCMS['maxpage']+1) : $total;$pages = ceil($total/$pagesize);}$max = min($offset+$pagesize, $total);for($i=$offset; $i<$max; $i++){$html->category($catid, $i);}
以下是一个栏目页及列表页模板的示例
复制代码
代码如下:
child) {$ismaxpage = 1;$page = min($page, $PHPCMS['maxpage']); /* 为了防止在地址栏输入页数,这里是要滴 */}?>
- {get sql="$sql" rows="20" page="$page" catid="$catid" ismaxpage="$ismaxpage"}
- {$r[title]} {/get}
经过以上这么一翻捣鼓,一开始的那效果就出来了。基本思路就是先要为get标签增加一个参数,用于判断是否开启“列表页最大页数”,然后生成静态页面的时候限制一下栏目页,不然它有多少生成多少。 PHPCMS 确实挺好,但需要改进的地方同样也很多,很多细节都没处理好,而有些功能都不是给人用的。希望 PHPCMS 能越来越强大!














发表评论