问题:帝国CMS模版使用自定义函数如何判断首页、栏目页、内容页以及其他页面?
答案:userfun.php文件添加get_page_type()函数,函数代码如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
function get_page_type() { global $navinfor, $navclassid, $enews,$searchid; // 内容页判断 if (isset($navinfor)) { $class= '内容页'; } // 栏目列表页判断 if (isset($navclassid) && $navclassid > 0 && !$navinfor) { $class= '栏目列表页'; } // 主页或自定义页面判断 if ($navclassid == 0 || empty($navclassid)) { $class= '主页'; if (isset($enews)) { if (strpos($enews, 'Userlist') !== false) { $class= '自定义列表页'; } elseif (strpos($enews, 'Userpage') !== false) { $class= '自定义内容页'; } } } //判断搜索页 if($searchid>0){ $class= '搜索页'; } return $class;} |
前台模版调用函数:
|
1
2
3
4
|
<?php$page_type = get_page_type(); echo "当前页面类型为: " . $page_type; ?> |
注:判断位置的全局变量有enews,navclassid,navinfor,searchid 可以多加其他页面的 比如最终下载页pathid
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。



评论(0)