zblog博客侧栏添加留言列表头像浏览列表显示头像代码zblog最新讨论显示头像代码

2018-10-21
0评论
/
1316阅读
爱搜啊

不知道大家有没有发现有的博客侧栏的浏览列表是带留言者头像的,而就那zblog博客举例,在后台模块管理默认最新讨论模块里面现实的是不带评论者头像的,这就很气了。如果想要让它现实头像,可以使用应用中心的插件实现,非常方便,具体是什么插件今天就不细说了。今天主要说下如何使用代码实现此功能

zblog博客侧栏添加留言列表头像浏览列表显示头像代码zblog最新讨论显示头像代码

要增加此功能,要先在当前使用主题的include.php文件内添加如下函数:

if (!function_exists('Sidebar_Module_Get_Comments')){
function Sidebar_Module_Get_Comments(){
   global $zbp;
   $i = 6; //数字6请自行替换为需要显示的评论个数
   $w=array();
   $w[]=array('=', 'comm_IsChecking', 0);
   $arr=explode(',','1'); //数字'1'请替换为管理员ID
   $w[]=array('NOT IN','comm_AuthorID',$arr);
   $comments = $zbp->GetCommentList(
   '*', 
   $w, 
   array('comm_PostTime' => 'DESC'), 
   $i, 
   null);
   return $comments;
}
}

当然了需要在<? php下面一行添加,这就不需要说了吧,然后要为侧栏评论列表显示头像添加CSS样式。打开主题的样式文件内添加如下代码,一般是/style/style.css文件

#divComments dd,#divComments ul{padding: 0;margin: 0;}
#divComments li{position:relative;width:100%;height:60px;overflow:hidden;padding:10px 10px 10px 60px;border:0;border-top:1px solid #eee;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;background-image:none;}
#divComments li:nth-child(1){border-top:0;}
#divComments li span.zb_avatar{position:absolute;left:10px;top:10px;width:40px;height:40px;}
.zb_avatar img{width:40px;height:40px;border-radius:50%;border:0;margin:0;padding:0;-webkit-transition:.4s;-webkit-transition:-webkit-transform.4s ease-out;transition:transform.4s ease-out;-moz-transition:-moz-transform.4s ease-out;}
#divComments li:hover .zb_avatar img{transform:rotateZ(60deg);-webkit-transform:rotateZ(60deg);-moz-transform:rotateZ(60deg);}
#divComments li small{line-height:20px;height:20px;overflow:hidden;font-size:11px;color:#999;display:block;border:0;margin:0;padding:0;}
#divComments li p{line-height:20px;height:20px;overflow:hidden;font-size:14px;display:block;margin:0 0 3px 0;padding:0;}

然后保存使用FTP软件上传到原来位置覆盖即可。第三步在主题template目录下添加最新留言模板文件,新建module-comments.php文件,内容如下:

{php}
$comments=Sidebar_Module_Get_Comments();
{/php}
{foreach $comments as $comment}
<li><span class="zb_avatar"><a href="{$comment->Post->Url}#cmt{$comment->ID}"><img src="{$comment->Author->Avatar}" alt="avatar"></a></span><p><a href="{$comment->Post->Url}#cmt{$comment->ID}">{TransferHTML($comment->Content, '[noenter]')}</a></p><small>{htmlspecialchars($comment->Author->StaticName)} 评论于:{$comment->Time('m-d')}</small></li>
{/foreach}

然后后台刷新缓存

zblog博客侧栏添加留言列表头像浏览列表显示头像代码zblog最新讨论显示头像代码

还有最后一步打开模块管理找到最新讨论,点击编辑重新提交一下到这里就好了,侧栏的评论列表已经有头像了,快去看看吧。

zblog博客侧栏添加留言列表头像浏览列表显示头像代码zblog最新讨论显示头像代码


本站附件分享,如果附件失效,可以去找找看

诚通网盘附件百度网盘附件


于2018-10-21发布