详情页

帝国cms 使用自定义函数如何判断首页、栏目页、内容页

时间:2024年05月30日

编辑:佚名

很简单,在userfun.php文件添加get_page_type()函数:
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;

前台模版调用函数
<?php
$page_type = get_page_type();  
echo "当前页面类型为: " . $page_type;  
?>
判断位置的全局变量有enews,navclassid,navinfor,searchid 可以多加其他页面的  比如最终下载页pathid
案例图:
相关文章
猜你需要