ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

ptootcms在列表页添加评论功能

2022-02-17 14:31:24  阅读:370  来源: 互联网

标签:sort ptootcms parser comment 列表 content 添加 评论 pboot


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

 

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

 

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])}这个自定义的标签。

 



最后的效果不错,虽然功能还暂时不是很全,还可以拓展评论点赞,回复评论的功能。

标签:sort,ptootcms,parser,comment,列表,content,添加,评论,pboot
来源: https://www.cnblogs.com/captain1024/p/15904501.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有