织梦首页/列表页直接获取软件模型本地下载地址


当使用软件模型而且只有一个下载地址时,我们都喜欢用本地地址,在列表页时直接输出这个地址,方便访客下载。

打开 \include\extend.func.php 添加个方法

/**
 *  获取软件模型本地地址
 *
 * @access    public
 * @param     string  $aid     文章id
 * @return    string
 */
if (!function_exists('GetDownLink'))
{
    function GetDownLink($aid)
    {
       global $dsql;
       $row= $dsql->GetOne("SELECT softlinks FROM `dede_addonsoft` WHERE aid = {$aid}");
           if(!is_array($row)){
            return '';
            }
           else{
            $dtp = new DedeTagParse();
            $dtp->LoadSource($row['softlinks']);
                foreach($dtp->CTags as $ctag)
                {
                    if($ctag->GetName()=='link')
                {
                    $link = trim($ctag->GetInnerText());
                }
            }
       }
       return  $link;
    }
}

 

前台模板中调用

首页/列表页 

[field:id function=GetDownLink(@me)/] 

内容页 

{dede:field.id function=GetDownLink(@me)/}