dede文章頁面如何顯示作者的頭像默認只能顯示作者用戶名

字號:


    dede在文章頁面顯示作者只是顯示其用戶名,但是假如我想把dede改造成較為社交化的網(wǎng)站,我覺得是有必要顯示作者的頭像的,但是官方并沒有相應的模版標簽。
    在網(wǎng)上看到解決這個問題的辦法基本上是直接在模版頁面調(diào)用runphp的程序段,的確這種辦法是可行的。
    但是我不傾向于這么做,因為很多時候我們都需要差異化的功能,每次都這樣夾雜著php代碼看起來很亂。
    我是直接在php文件里面修改的,讓文章模版可以調(diào)用幾個新的標簽。
    找到/include/arc.archives.class.php文件
    搜索“$this->addTableRow=$this->dsql->GetOne($query);”,跳轉(zhuǎn)到大概154行,在else{$this->Fields['templet']=$this->Fields['redirecturl']='';}下面添加如下代碼:
    代碼如下:
    /*HEJIE_MODIFY*/
    $query="SELECT*FROMjcode_memberWHERE`mid`=".$this->Fields['mid'];
    $authorInfo=$this->dsql->GetOne($query);
    $this->Fields['authoranme']=$authorInfo['uname'];
    $this->Fields['authorface']=$authorInfo['face'];
    if(empty($this->Fields['authorface']))
    {
    $this->Fields['authorface']=($this->authorInfo['sex']=='女')?'../member/templets/images/dfgirl.png':'../member/templets/images/dfboy.png';
    }
    $this->Fields['authorface']="<ahref='".$GLOBALS['cfg_basehost']."/member/index.php?uid=".$authorInfo['userid']."'><imgwidth='32'height='32'src='".$this->Fields['authorface']."'/></a>";
    $this->Fields['authoremail']=$authorInfo['email'];
    這段代碼的作用就是根據(jù)文章的作者id查詢作者信息,其中當然包括頭像。
    我這里為了以后備用查詢出了頭像email和用戶名稱三種信息。
    在用戶頭像的這個標簽里面我做了一些處理,使在模版中調(diào)用的時候能直接生成鏈接,指向作者的空間。
    在文章模板中調(diào)用作者頭像的語句為:
    代碼如下:
    {dede:field.authorface/}
    這個標簽對應的php代碼其實就是上面的$this->Fields['authorface'],同理我們要查詢出作者的email信息其實是在php代碼的$this->Fields['authoremail']中,對應的模版標簽為{dede:field.authoremail/}