码迷,mamicode.com
首页 > 其他好文 > 详细

[二次开发]dede文章页面如何显示作者的头像

时间:2014-07-01 07:28:37      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   width   文件   2014   

dede在文章页面显示作者只是显示其用户名,但是假如我想把dede改造成较为社交化的网站,我觉得是有必要显示作者的头像的,但是官方并没有相应的模版标签。
在网上看到解决这个问题的办法基本上是直接在模版页面调用runphp的程序段,的确这种办法是可行的。
但是我不倾向于这么做,因为很多时候我们都需要差异化的功能,每次都这样夹杂着php代码看起来很乱。

我是直接在php文件里面修改的,让文章模版可以调用几个新的标签。
找到/include/arc.archives.class.php文件
搜索“$this->addTableRow = $this->dsql->GetOne($query);”,跳转到大概154行,在else{    $this->Fields[‘templet‘] = $this->Fields[‘redirecturl‘] = ‘‘;}下面添加如下代码:

/*HEJIE_MODIFY文章作者信息 @www.68cpu.com*/
$query = "SELECT * FROM jcode_member WHERE `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']="<a href='".$GLOBALS['cfg_basehost']."/member/index.php?uid=".$authorInfo['userid']."'><img width='32' height='32' src='".$this->Fields['authorface']."' /></a>";
$this->Fields['authoremail']=$authorInfo['email'];

这段代码的作用就是根据文章的作者id查询作者信息,其中当然包括头像。
我这里为了以后备用查询出了头像 email 和用户名称三种信息。
在用户头像的这个标签里面我做了一些处理,使在模版中调用的时候能直接生成链接,指向作者的空间。
在文章模板中调用作者头像的语句为:
{dede:field.authorface/}
这个标签对应的php代码其实就是上面的$this->Fields[‘authorface‘],同理我们要查询出作者的email信息其实是在php代码的$this->Fields[‘authoremail‘]中,对应的模版标签为{dede:field.authoremail/}

[二次开发]dede文章页面如何显示作者的头像,布布扣,bubuko.com

[二次开发]dede文章页面如何显示作者的头像

标签:style   blog   color   width   文件   2014   

原文地址:http://blog.csdn.net/qikexun/article/details/36007647

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!