ptootcms如何在列表页添加评论功能

最近需要在列表页里添加文章评论,大概是图片这个样子。

现在还处于静态的,那功能怎么实现呢?要知道,文章评论调用当前只能在内容详情页可用。

1,在后台系统里修改,配置参数 》会员配置里修改配置,评论功能开启,评论验证码关闭,评论审核关闭。

2,在ExtLabelController.php添加方法。

路径:/apps/home/controller/IndexController.php

作用:该文件的作用之一,是将已经写好的功能添加到对应的单页或列表页中。

修改:大约在249行,在“$content = $this->parser->parserAfter($content); // CMS公共标签后置解析”的下面添加新的功能。

// 列表
   private function getListPage($sort)
   {
       // 调用栏目语言与当前语言不一致时,自动切换语言
       if ($sort->acode != get_lg() && Config::get('lgautosw') !== '0') {
           cookie('lg', $sort->acode);
       }
       if ($sort->listtpl) {
           $this->checkPageLevel($sort->gcode, $sort->gtype, $sort->gnote);
           $content = parent::parser($this->htmldir . $sort->listtpl); // 框架标签解析
           $content = $this->parser->parserBefore($content); // CMS公共标签前置解析
           $pagetitle = $sort->title ? "{sort:title}" : "{sort:name}"; // 页面标题
           $content = str_replace('{pboot:pagetitle}', $this->config('list_title') ?: ($pagetitle . '-{pboot:sitetitle}-{pboot:sitesubtitle}'), $content);
           $content = str_replace('{pboot:pagekeywords}', '{sort:keywords}', $content);
           $content = str_replace('{pboot:pagedescription}', '{sort:description}', $content);
           $content = $this->parser->parserPositionLabel($content, $sort->scode); // CMS当前位置标签解析
           $content = $this->parser->parserSortLabel($content, $sort); // CMS分类信息标签解析
           $content = $this->parser->parserListLabel($content, $sort->scode); // CMS分类列表标签解析
           $content = $this->parser->parserAfter($content); // CMS公共标签后置解析
   $content = $this->parser->parserCommentLabel($content); // 文章评论
       } else {
           error('请到后台设置分类栏目列表页模板!');
       }
       $this->cache($content, true);
   }

添加的代码在该文件的其他地方也能看到:

$content = $this->parser->parserCommentLabel($content); // 文章评论

3,ExtLabelController.php添加新的方法,统计当前文章评论数。

路径:/apps/home/controller/ExtLabelController.php

修改:大约在35行,在“private function test()”的方法下面添加新的方法。

//获得评论数量private function getcommentrows()
{  
   $pattern = '/\{getcommentrows\s?\(([^\}]+)\)\}/';    if (preg_match($pattern, $this->content, $matches)) {        $this->content = preg_replace_callback(        $pattern,        function($matches){            $extfield = $matches[1];            $result = \core\basic\Db::table('`ay_member_comment` a ')->field('count(*) as count')            ->where("a.contentid='".$extfield."' AND pid = 0 AND a.status=1")            ->find();            $value = $result->count;            return $value;
                   
       },        $this->content);
   }
}

然后在run()方法里面执行该方法

public function run($content)
{    // 接收数据
   $this->content = $content;    
   // 执行个人自定义标签函数
   $this->test();    
   //获得评论数
   $this->getcommentrows();    
   // 返回数据
   return $this->content;
}

4,在列表页模板上添加代码

{pboot:list}<div class="col-xs-12 pad0 {pboot:if('[list:n]'>'0')}mt15{/pboot:if}">
   
   <div class="bottom mt15">
       <form action="/comment/add/?contentid=[list:id]"  method="post">
           <div class="clear-fix flex fayan">
               <input type="text"  name="comment" id="comment" value="" placeholder="参与评论" />
               <input type="submit" id="" name="" value="评论" />
           </div>
       </form>
       <div class="pinglun">
           {pboot:comment contentid=[list:id] page=0}            <div class="plitem"><span>[comment:nickname] : </span>[comment:comment]</div>
           {/pboot:comment}            <div class="plitem"><a href=""><span>查看全部{getcommentrows([list:id])}条评论</span></a></div>
       </div>
   </div>
   
</div>{/pboot:list}

发布评论的表单是

<form action="/comment/add/?contentid=[list:id]"  method="post">
<div class="clear-fix flex fayan">
<input type="text"  name="comment" id="comment" value="" placeholder="参与评论" />
<input type="submit" id="" name="" value="评论" />
</div>
</form>

读取评论的表单是

{pboot:comment contentid=[list:id] page=0}<div class="plitem"><span>[comment:nickname] : </span>[comment:comment]</div>{/pboot:comment}
pboot:comment 标签需要参数page=0

最后多少条评论用{getcommentrows([list:id])}这个自定义的标签。
最后的效果不错,虽然功能还暂时不是很全,还可以拓展评论点赞,回复评论的功能。

原文地址:https://www.cnblogs.com/captain1024/p/15904501.html

收藏 (0) 打赏

感谢您的支持,我会继续努力的!

打开微信/支付宝扫一扫,即可进行扫码打赏哦,分享从这里开始,精彩与您同在
点赞 (0)

免责声明:本文系转载自互联网,版权归原作者所有;旨在传递信息,不代表中站源码网的观点和立场。如有侵权,请联系我们删除!qin@ceccz.com

中站源码网-网络情报局 PbootCMS教程与问题 ptootcms如何在列表页添加评论功能 https://web.ceccz.com/cmsjc/pbwt/3293.html

中站网

常见问题
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。更多说明请参考 VIP介绍。
查看详情
  • 最常见的情况是下载不完整: 可对比下载完压缩包的与网盘上的容量,若小于网盘提示的容量则是这个原因。这是浏览器下载的bug,建议换浏览器下载!
查看详情

相关文章

评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务

 
ptootcms如何在列表页添加评论功能-海报

分享本文封面