IT技术互动交流平台

DedeCMS获取文档及栏目所在链接URL之扩展方法

作者:影诺  发布日期:2013-09-26 10:30:09
/** 
 * 获取栏目完整URL路径 by Windchaser QQ:939238564 
 * @param   $typeid  栏目ID|文档ID 
 * @link    http://down.chinaz.com/try/201202/1646_1.htm   从该文章代码基础上改编 
 * @return  String 
 */
function typeurl_arc($typeid,$type='tid'){ 
    global $dsql,$cfg_basehost; 
    if($type == 'tid'){//获取栏目完整URL地址 
        $typeurl = ''; 
        $row = $dsql ->GetOne("SELECT typedir,namerule2,isdefault,typedir,defaultname FROM #@__arctype WHERE id=$typeid"); 
        $row['namerule2'] = str_replace('{typedir}','',$row['namerule2']); 
        $row['namerule2'] = str_replace('{tid}',$typeid,$row['namerule2']); 
        $row['namerule2'] = str_replace('{page}',1,$row['namerule2']); 
        $row['typedir'] = str_replace('{cmspath}','',$row['typedir']); 
        switch ($row['isdefault']) { 
            case 0://链接到列表第一页 
                $typeurl = $row['namerule2']; 
                break; 
            case 1://链接到默认页 
                $typeurl = $row['typedir'].'/'.$row['defaultname']; 
                break; 
            default://使用动态页 
                $typeurl = '/plug/list.php?tid='.$typeid; 
                break; 
        } 
    }else if($type == 'aid'){//获取文档完整URL地址 
        $row = $dsql ->GetOne("SELECT cnn.namerule,arc.ismake,arc.senddate FROM #@__archives arc JOIN #@__arctype cnn ON arc.typeid=cnn.id WHERE arc.id=$typeid"); 
        if($row['ismake'] == 1){ 
            if(strpos($row['namerule'],'/') == 0){ 
                $row['namerule'] = substr($row['namerule'],1); 
            } 
            $row['namerule'] = str_replace('{aid}',$typeid,$row['namerule']); 
            $row['namerule'] = str_replace('{Y}',date('Y',$row['senddate']),$row['namerule']); 
            $row['namerule'] = str_replace('{M}',date('m',$row['senddate']),$row['namerule']); 
            $row['namerule'] = str_replace('{D}',date('d',$row['senddate']),$row['namerule']); 
            $typeurl = '/'.$row['namerule']; 
        }else{ 
            $typeurl = '/plug/view.php?aid='.$typeid; 
        }       
    } 
    $typeurl = $cfg_basehost.$typeurl; 
    return $typeurl; 
}

DEDECMS模版标签的一个扩展方法!

目的是获取栏目或者文档的完整URL地址!

文档和列表的标签调用小有不同!

列表:


{dede:field.typeid function='typeurl_arc(@me)'/}

文档:
 

{dede:field.id function='typeurl_arc(@me,aid)'/}

 

Tag标签: DedeCMS  
  • 专题推荐

About IT165 - 广告服务 - 隐私声明 - 版权申明 - 免责条款 - 网站地图 - 网友投稿 - 联系方式
本站内容来自于互联网,仅供用于网络技术学习,学习中请遵循相关法律法规