上次,余斗教大家《DedeCMS添加自定义函数function的方法》,今天余斗就给大家展示几个常用的自定义函数,大家可以在以后的做站过程中灵活使用,所有的代码均添加在自定义函数文include/extend.func.php中:

//通过会员ID查看会员名称的函数

function GetMemberName($str){

$dsql =
new Dedesql(
false);

$row = $dsql->GetOne(
“SELECT uname FROM `ddmx_member` WHERE mid = ‘$str’ “);


return $row[uname];

}

 

前台模板调用:

[field:mid function=
“GetMemberName(@me)”/]

 

//通过ID号获取类别的链接

function GetTypeUrl($tid)

{

  global $dsql;

  global $cfg_cmspath;

  $query =
“select typedir from ‘#` where ;

 
if($row=$dsql->getone($query))

  {

    $temp=str_replace(
“{cmspath}”,$cfg_cmspath,$row[
‘typedir’]).
‘/’;

  }

 
return $temp;

}

 

前台模板调用:

[field:mid function=
“GetTypeUrl(@me)”/]

 

//通过ID号获取文章的链接

function zGetArticleUrl($id)

{

  global $dsql;

  global $cfg_cmspath;

  $query =
“select id,typedir,namerule from ‘#` where typeid from ‘#` where ;

 
if($row = $dsql->getone($query))

  {

    $arc=$row[
‘namerule’];

    $type=str_replace(
“{cmspath}”,$cfg_cmspath,$row[
‘typedir’]);

    $temp=str_replace(
“{typedir}”,$type,$temp);

    $temp=str_replace(
“{aid}”,$id,$temp);

  }

 
return $temp;

}

 

前台模板调用:

[field:mid function=
“zGetArticleUrl(@me)”/]

 

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。