欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

PHPCMS 欄目頁及列表頁分頁修改

  發(fā)布時(shí)間:2011-09-13 16:14:16   作者:佚名   我要評(píng)論
如果你有用過PHPCMS做二次開發(fā),你也許會(huì)注意到后臺(tái)的“列表頁最大頁數(shù)”這個(gè)參數(shù)無論你怎么設(shè)置都不起作用。結(jié)合剛做的一個(gè)網(wǎng)站,偶就分享一下解決方法吧,也免得以后忘了。
網(wǎng)站欄目頁及列表頁要實(shí)現(xiàn)的效果如下:
1、欄目頁最多只列出100頁;
2、列表頁不限制最大頁數(shù),有多少頁就列出多少頁。
要實(shí)現(xiàn)這個(gè)效果,需要改動(dòng)的文件有3個(gè),文件及改動(dòng)內(nèi)容如下:

復(fù)制代碼
代碼如下:

/*
文件:/include/global.func.php
函數(shù):get
*/
/*
為 get 函數(shù)添加一個(gè)參數(shù)
ismaxpage 就是所添加的參數(shù),用于判斷是否啟用“列表頁最大頁數(shù)”這個(gè)參數(shù)
而插入代碼的部分是為了改變total的值,即記錄集總數(shù)
*/
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);
}
/* 插入以上代碼 結(jié)束 */
$pages = pages($total, $page, $rows, $urlrule, '', $catid);
...
}


復(fù)制代碼
代碼如下:

/*
文件:/include/template.func.php
函數(shù):get_parse
*/
/*
前臺(tái) get 標(biāo)簽最后是轉(zhuǎn)換成 get 函數(shù),以下是處理 get 標(biāo)簽的函數(shù)
因?yàn)?get 函數(shù)增加了一個(gè)參數(shù) $ismaxpage,所以這里也需要做相應(yīng)修改
以下是修改后的部分代碼
*/
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 這個(gè)參數(shù),仔細(xì)看 */
$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++;?>";
}
...
}


復(fù)制代碼
代碼如下:

/*
文件:/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;
/* 以下這行代碼確保了生成的欄目及列表頁的數(shù)量是正確的,該生成多少頁就是多少頁 */
$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);
}

以下是一個(gè)欄目頁及列表頁模板的示例


復(fù)制代碼
代碼如下:

<?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";
/* 判斷是否有子欄目,有的話就開啟“列表頁最大頁數(shù)”這個(gè)參數(shù),限制欄目頁頁數(shù) */
if ($child) {
$ismaxpage = 1;
$page = min($page, $PHPCMS['maxpage']); /* 為了防止在地址欄輸入頁數(shù),這里是要滴 */
}
?>
<ul>
{get sql="$sql" rows="20" page="$page" catid="$catid" ismaxpage="$ismaxpage"}
<li>{$r[title]}</li>
{/get}
</ul>
<div>{$pages}</div>

經(jīng)過以上這么一翻搗鼓,一開始的那效果就出來了。基本思路就是先要為get標(biāo)簽增加一個(gè)參數(shù),用于判斷是否開啟“列表頁最大頁數(shù)”,然后生成靜態(tài)頁面的時(shí)候限制一下欄目頁,不然它有多少生成多少。
PHPCMS 確實(shí)挺好,但需要改進(jìn)的地方同樣也很多,很多細(xì)節(jié)都沒處理好,而有些功能都不是給人用的。希望 PHPCMS 能越來越強(qiáng)大!

相關(guān)文章

最新評(píng)論