织梦DEDECMS显示和内容有关的专题标题内容


我们在使用织梦DEDECMS制作文章页或者列表页模板时候,都希望在页面中显示和内容有关的标题或者专题内容,如何在DEDECMS文章模板中调用和内容有关的专题标题,这个我们需要修改DEDECMS相关的PHP文件来实现。

打开include/extend.func.php,在最后添加:

 

 

function getlikespc($keywords=0)   
{   
    global $cfg_basehost,$dsql;   
 $key = array();   
 $key = explode(",",$keywords);   
 $likesql;   
 $len =count($key);   
 for($i=0;$i<$len;$i++){   
  $now = $len-$i;   
  if($now==1){   
   $likesql .= "keywords like '%".$key[$i]."%' ";   
 }else{   
   $likesql .= "keywords like '%".$key[$i]."%' or ";   
  }   
 }//关键字分割检索,拼接 查询语句   
 $getsql = "SELECT * from  dede_archives where dede_archives.channel='-1'  
and $likesql order by  dede_archives.id ";//查询与该文章关键字相同的专题   
 //echo $getsql;   
 $toback;   
    $dsql->Execute("m",$getsql);   
 while($row = $dsql->GetObject('m'))   
    {   
        $title = $row->title;//专题标题   
  $id = $row->id;//专题ID   
  $toback = "<a href='".$cfg_basehost."/special/arc-".$id.".html' >".$title."</a>";   
    }   
    return $toback;//返回文章链接   
}

{dede:field.keywords function=’getlikespc(@me)’/} 然后在你想调用相关专题的地方加入下面代码即可: