PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通PHP建站技术分享-从入门到精通

QQ:420220301 微信/手机:150-3210-7690
当前位置:首页 > CMS教程 > 极致CMS

评论功能

管理员 2024-12-14
极致CMS
13

基本使用

评论需要登录会员才可以使用,但是,目前评论类互联网审核比较严格,所以,一般不建议开放评论。

评论条数统计

内容页

{fun M('comment')->getCount(['isshow'=>1,'aid'=>$jz['id'],'tid'=>$jz['tid']])}

指定用户评论条数

用户ID=1

{fun M('comment')->getCount(['isshow'=>1,'userid'=>1])}

评论封装

注意:需要引入 layui 和 jquery,当前模块封装的是内容页变量,其他页面请自行修改!!!

  <div class="comment-area section-space--pt_60 section-space--pb_100">    <div class="container">    <div class="row comment-area section-space--pt_60">      <div class="m-auto">        <div class="comment-list-wrapper">          <h3 class="widget-title mb-30">评论 (<span id="jz_comment_num">{$jz['comment_num']}</span>)</h3>          <ol class="comment-list" id="jz_comment_list">                      </ol>          <div class="comment-page-bar">          <span class="comment-page" onclick="prevmessagelist()" >上一页</span>          <span class="comment-page" onclick="nextmessagelist()" >下一页</span>          </div>        </div>      </div>    </div>    <div class="row comment-area section-space--pt_60">      <div class="section-title">        <h3 class="title">我要点评</h3>      </div>      <form action="" class="comment-form-area">        <div class="row">        <input name="go" value="1" placeholder="表示" id="go" type="hidden" />        <input name="star" value="0" placeholder="评论星星数"  id="star" type="hidden" />        <input name="tid" id="tid" value="{$type['id']}"  type="hidden" />        <input name="aid" id="aid" value="{$jz['id']}" placeholder="文章ID"   type="hidden" />        <input name="zid" value="0" id="zid" placeholder="评论层ID"  type="hidden" />        <input name="pid" value="0" id="pid" placeholder="回复层ID"  type="hidden" />          <div class="col-lg-12">            <div class="single-input">              <textarea                id="content"                name="textarea"                {if(!$islogin)}disabled{/if}                placeholder="输入评论内容"              ></textarea>            </div>          </div>          <div class="col-lg-12">          {if($islogin)}            <div class="submit-button text-center">              <button                class="btn-large btn-primary"                type="button"                onclick="sendmsg()"              >                提 交              </button>            </div>           {else}           您还未登录,无法发表评论!<button type="button" class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#loginModel">立即登录</button>           {/if}          </div>        </div>      </form>    </div>                  </div>    </div>        <script>    //发送评论    function sendmsg(){        var star = $("#star").val();        var tid = $("#tid").val();        var aid = $("#aid").val();        var zid = $("#zid").val();        var pid = $("#pid").val();        var content = $("#content").val();        if(content==''){            layer.alert('评论内容不能为空!');            return false;        }        $.post('/comment/index',{star:star,tid:tid,aid:aid,zid:zid,pid:pid,body:content,ajax:1,go:1},function(res){            if(res.code==0){                layer.msg(res.msg,{icon:6,time:2000},function(){                    location.reload();                })            }else{                layer.msg(res.msg,{icon:5,time:2000})            }        },'json');                return false;                    }    function reply(pid,username,zid){        $("#pid").val(pid);        $("#zid").val(zid);        $("#content").val('[@'+username+']');        $("#content").focus();    }    //获取评论列表    function getmessagelist(tid,aid,page){        $.ajax({             url:"/comment/getlist",             dataType:"json",             data:{tid:tid,aid:aid,page:page,limit:10},             async:true,             type:"GET",             success:function(r){                if(r.code==0){                    var len = r.data.list.length;                    var html = '';                    if(len>0){                        for(var i=0;i<len;i++){                            var rdata = r.data.list[i];                            html+='<li class="comment">'+                                  '<div class="comment-2">'+                                    '<div class="comment-author-info">'+                                      '<div class="comment-author vcard">'+                                        '<img alt="'+rdata.user.username+'" src="'+rdata.user.litpic+'" onerror="this.src='{$tpl}static/picture/comments-3.png'" />'+                                      '</div>'+                                      '<div class="comment-content">'+                                        '<div class="meta">'+                                          '<div class="comment-content-top">'+                                            '<div class="comment-actions">'+                                              '<h6 class="fn">'+rdata.user.username+'</h6>'+                                              '<span class="time">'+rdata.addtime+'</span>'+                                            '</div>'+                                          '</div>'+                                          '<a class="comment-reply-link" onclick="reply('+rdata.id+',''+rdata.user.username+'','+rdata.id+')"><i class="icofont-reply"></i> 回复</a>'+                                        '</div>'+                                      '</div>'+                                    '</div>'+                                    '<div class="comment-text">'+                                      '<p>'+rdata.body+                                      '</p>'+                                    '</div>'+                                  '</div>';                            var llen = rdata.children.length;                            if(llen>0){                                html+='<ol class="children">';                                for(var j=0;j<llen;j++){                                    var rrdata = rdata.children[j];                                    html+='<li class="comment">'+                                  '<div class="comment-2">'+                                    '<div class="comment-author-info">'+                                      '<div class="comment-author vcard">'+                                        '<img alt="'+rrdata.user.username+'" src="'+rrdata.user.litpic+'" onerror="this.src='{$tpl}static/picture/comments-3.png'" />'+                                      '</div>'+                                      '<div class="comment-content">'+                                        '<div class="meta">'+                                          '<div class="comment-content-top">'+                                            '<div class="comment-actions">'+                                              '<h6 class="fn">'+rrdata.user.username+'</h6>'+                                              '<span class="time">'+rrdata.addtime+'</span>'+                                            '</div>'+                                          '</div>'+                                          '<a class="comment-reply-link" onclick="reply('+rrdata.id+',''+rrdata.user.username+'','+rdata.id+')"><i class="icofont-reply"></i> 回复</a>'+                                        '</div>'+                                      '</div>'+                                    '</div>'+                                    '<div class="comment-text">'+                                      '<p>'+rrdata.body+                                      '</p>'+                                    '</div>'+                                  '</div>';                                }                                html+='</ol>';                            }                            html+='</li>';                        }                                $("#jz_comment_list").html(html);                    }else{                        var page = r.data.allpage;                        //layer.msg('没有了',{icon:6,time:1000});                    }                                        $("#jz_comment_num").html(r.data.count);                    var allpage = parseInt(r.data.allpage);                    if(allpage>1){                        $(".comment-page-bar").show();                    }else{                        $(".comment-page-bar").hide();                    }                                    }             }        })    }    //下一页评论    function nextmessagelist(){        page++;        var tid = $("#tid").val();        var aid = $("#aid").val();        getmessagelist(tid,aid,page)    }    //上一页评论    function prevmessagelist(){        page = page--;        page = page<0 ? 1 : page;        var tid = $("#tid").val();        var aid = $("#aid").val();        getmessagelist(tid,aid,page)    }                 var page = 1;     //内容页变量,其他页面请自行修改     getmessagelist({$jz['tid']},{$jz['id']},page);        //回复其他人        function reply(pid,username){        $("#pid").val(pid);        $("#content").val('[@'+username+']');        $("#content").focus();    }        </script>

输出指定用户评论内容

假设用户ID=1

{loop table="comment" userid="1" as="v"}{php$user = memberInfo($v['userid']);/}评论用户:{$user['username']}用户头像:{$user['litpic']}评论内容:{$v['body']}评论时间:{fun date('Y-m-d H:i:s',$v['addtime'])}{/loop}


如果要指定文章内的评论,请加上对应的参数 aid 和 tid


根据文章输出对应评论

文章ID=1,栏目ID=2

{loop table="comment" aid="1" tid="2" as="v"}{php$user = memberInfo($v['userid']);/}评论用户:{$user['username']}用户头像:{$user['litpic']}评论内容:{$v['body']}评论时间:{fun date('Y-m-d H:i:s',$v['addtime'])}{/loop}



希望以上内容对你有所帮助!如果还有其他问题,请随时提问。 各类知识收集 拥有多年CMS企业建站经验,对 iCMS, Fastadmin, ClassCMS, LeCMS, PbootCMS, PHPCMS, 易优CMS, YzmCMS, 讯睿CMS, 极致CMS, Wordpress, HkCMS, YznCMS, WellCMS, ThinkCMF, 等各类cms的相互转化,程序开发,网站制作,bug修复,程序杀毒,插件定制都可以提供最佳解决方案。

相关推荐

扫码关注

qrcode

QQ交谈

回顶部