中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

PHPCMS 欄目頁(yè)及列表頁(yè)分頁(yè)修改

1970-01-01    來(lái)源:

容器云強(qiáng)勢(shì)上線!快速搭建集群,上萬(wàn)Linux鏡像隨意使用
網(wǎng)站欄目頁(yè)及列表頁(yè)要實(shí)現(xiàn)的效果如下:
1、欄目頁(yè)最多只列出100頁(yè);
2、列表頁(yè)不限制最大頁(yè)數(shù),有多少頁(yè)就列出多少頁(yè)。
要實(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ù),用于判斷是否啟用“列表頁(yè)最大頁(yè)數(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{
$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;
/* 以下這行代碼確保了生成的欄目及列表頁(yè)的數(shù)量是正確的,該生成多少頁(yè)就是多少頁(yè) */
$total = $CATEGORY[$catid]['child'] ? min($total, $PHPCMS['maxpage']+1) : $total;
$pages = ceil($total/$pagesize);
}
$max = min($offset+$pagesize, $total);
for($i=$offset; $i{
$html->category($catid, $i);
}

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


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

    {get sql="$sql" rows="20" page="$page" catid="$catid" ismaxpage="$ismaxpage"}
  • {$r[title]}

  • {/get}

{$pages}


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

標(biāo)簽: 代碼 網(wǎng)站

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請(qǐng)聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點(diǎn)!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請(qǐng)與原作者聯(lián)系。

上一篇:PHPCMS中實(shí)現(xiàn)網(wǎng)站變成黑白的方法代碼

下一篇:PHPCMS網(wǎng)站轉(zhuǎn)移空間教程