我們在使用織夢DEDECMS制作文章頁或者列表頁模板時候,都希望在頁面中顯示和內(nèi)容有關(guān)的標題或者專題內(nèi)容,如何在DEDECMS文章模板中調(diào)用和內(nèi)容有關(guān)的專題標題,這個我們需要修改DEDECMS相關(guān)的PHP文件來實現(xiàn)。
打開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 "; } }//關(guān)鍵字分割檢索,拼接 查詢語句 $getsql = "SELECT * from dede_archives where dede_archives.channel='-1' and $likesql order by dede_archives.id ";//查詢與該文章關(guān)鍵字相同的專題 //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)'/} 然后在你想調(diào)用相關(guān)專題的地方加入下面代碼即可:



















