具体步骤如下:
首先,找到/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']="
";
$this->Fields['authoremail']=$authorInfo['email'];
这段代码的作用是根据文章的作者ID查询作者信息,其中包括头像、邮箱和用户名等信息。为了方便后续使用,这里查询出了头像、邮箱和用户名称三种信息。
对于用户头像这个标签,我还做了一些处理,使得在模板中调用时能直接生成链接,指向作者的空间。
在文章模板中调用作者头像的语句为:
{dede:field.authorface/}
这个标签对应的PHP代码其实就是上面的$this->Fields['authorface']。同理,我们要查询出作者的邮箱信息其实是在PHP代码的$this->Fields['authoremail']中,对应的模板标签为{dede:field.authoremail/}。
通过这种方式,我们不仅可以让文章页面显示作者的头像,还可以根据需要显示更多关于作者的信息,从而提升网站的社交化程度和用户体验。