网站栏目页及列表页要实现的效果如下:
1、栏目页最多只列出100页;
2、列表页不限制最大页数,有多少页就列出多少页。
要实现这个效果,需要改动的文件有3个,文件及改动内容如下:
复制代码代码如下:
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);
...
}
复制代码代码如下:
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))
{
$str = "<?php \$ARRAY = get(\"$sql\", $rows, $page, \"$dbname\", \"$dbsource\", \"$urlrule\",\"$distinctfield\",\"$catid\", $ismaxpage);\$DATA=\$ARRAY['data'];\$total=\$ARRAY['total'];\$count=\$ARRAY['count'];\$pages=\$ARRAY['pages'];unset(\$ARRAY);foreach(\$DATA AS \$n=>\${$return}){\$n++;?>";
}
...
}
复制代码代码如下:
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);
}
以下是一个栏目页及列表页模板的示例
复制代码代码如下:
<?php
$catids = str_replace('`catid`', 'a.`catid`', get_sql_catid($catid));
$sql = "
SELECT a.contentid, a.catid, a.title, a.keywords, a.thumb, a.userid, a.updatetime, a.inputtime, a.islink, a.url, a.style
FROM `phpcms_content` a
WHERE a.status=99 $catids ORDER BY a.contentid DESC";
if ($child) {
$ismaxpage = 1;
$page = min($page, $PHPCMS['maxpage']);
}
?>
<ul>
{get sql="$sql" rows="20" page="$page" catid="$catid" ismaxpage="$ismaxpage"}
<li>{$r[title]}</li>
{/get}
</ul>
<div>{$pages}</div>
经过以上这么一翻捣鼓,一开始的那效果就出来了。基本思路就是先要为get标签增加一个参数,用于判断是否开启“列表页最大页数”,然后生成静态页面的时候限制一下栏目页,不然它有多少生成多少。
PHPCMS 确实挺好,但需要改进的地方同样也很多,很多细节都没处理好,而有些功能都不是给人用的。希望 PHPCMS 能越来越强大!