吴坚 發表於 2023-12-27 00:00:00

dede文章页面如何显示作者的头像默认只能显示作者用户名

<p>
        <span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>dede在文章页面显示作者只是显示其用户名,但是假如我想把dede改造成较为社交化的网站,我觉得是有必要显示作者的<u>头像</u>的,但是官方并没有相应的模版标签。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在网上看到解决这个问题的办法基本上是直接在模版页面调用runphp的程序段,的确这种办法是可行的。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>但是我不倾向于这么做,因为很多时候我们都需要差异化的功能,每次都这样夹杂着php代码看起来很乱。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我是直接在php文件里面修改的,让文章模版可以调用几个新的标签。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>找到/include/arc.archives.class.php文件 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>搜索“$this-&gt;addTableRow = $this-&gt;dsql-&gt;GetOne($query);”,跳转到大概154行,在else{ $this-&gt;Fields['templet'] = $this-&gt;Fields['redirecturl'] = '';}下面添加如下代码: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        /*HEJIE_MODIFY文章作者信息 @www.jb51.net*/ <br>
        $query = "SELECT * FROM jcode_member WHERE `mid` = ".$this-&gt;Fields['mid']; <br>
        $authorInfo = $this-&gt;dsql-&gt;GetOne($query); <br>
        $this-&gt;Fields['authoranme']=$authorInfo['uname']; <br>
        $this-&gt;Fields['authorface']=$authorInfo['face']; <br>
        if(empty($this-&gt;Fields['authorface'])) <br>
        { <br>
        $this-&gt;Fields['authorface']=($this-&gt;authorInfo['sex']=='女')? '../member/templets/images/dfgirl.png' : '../member/templets/images/dfboy.png'; <br>
        } <br>
        $this-&gt;Fields['authorface']="&lt;a href='".$GLOBALS['cfg_basehost']."/member/index.php?uid=".$authorInfo['userid']."'&gt;&lt;img width='32' height='32' src='".$this-&gt;Fields['authorface']."' /&gt;&lt;/a&gt;"; <br>
        $this-&gt;Fields['authoremail']=$authorInfo['email']; </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这段代码的作用就是根据文章的作者id查询作者信息,其中当然包括头像。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>我这里为了以后备用查询出了头像 email 和用户名称三种信息。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在用户头像的这个标签里面我做了一些处理,使在模版中调用的时候能直接生成链接,指向作者的空间。 </span><br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>在文章模板中调用作者头像的语句为: </span></p>
<div class="msgheader" style='margin: 3px auto 0px; padding: 0px 3px; outline: none; line-height: 21.6px; clear: both; border-width: 1px; border-style: solid; border-color: rgb(0, 153, 204); background: rgb(246, 251, 255); overflow: hidden; font-family: tahoma, arial, "Microsoft YaHei";'>
        <p class="right">
                <span><u>复制代码</u></span></p>
        <p>
                代码如下:</p>
</div>
<p class="msgborder" style='margin: 0px auto 3px; padding: 0px 3px; outline: none; line-height: 25.2px; font-size: 14px; clear: both; border-right: 1px solid rgb(0, 153, 204); background: rgb(221, 237, 251); overflow: hidden; border-left: 1px solid rgb(0, 153, 204); word-break: break-all; border-bottom: 1px solid rgb(0, 153, 204); word-wrap: break-word; font-family: tahoma, arial, "Microsoft YaHei";'>
        <br>
        {dede:field.authorface/} </p>
<p>
        <br style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'><span style='font-family: tahoma, arial, "Microsoft YaHei"; font-size: 14px;'>这个标签对应的php代码其实就是上面的$this-&gt;Fields['authorface'],同理我们要查询出作者的email信息其实是在php代码的$this-&gt;Fields['authoremail']中,对应的模版标签为{dede:field.authoremail/}</span></p>
頁: [1]
查看完整版本: dede文章页面如何显示作者的头像默认只能显示作者用户名