帝国CMS:回复评论后文章才能完整显示的实现方法

1.在内容模板里面加入<div id=”textshow”></div>

2.在模板尾部加入
<script src=”[!–news.url–]skin/news/js/jquery-1.7.2.min.js” type=”text/javascript”></script>
<script>
(function (win, $) {
$.listnews = {
initGetData(index) {
$.ajax({
url: ‘[!–news.url–]e/extend/text/?id=[!–id–]&classid=[!–classid–]’,
type: ‘get’,
dataType: ‘json’,
success: function (jsonData) {
var html = ”;
if (jsonData.info) {
jsonData.info.forEach(function (val) {
html += `<div class=”list_news_box”>${val.newstext}</div>`;
})
$(‘#textshow’).append(html);
}
}
})
},
init() {
this.initGetData();
}
}
$.listnews.init();
})(window, jQuery)
</script>

3.把下面代码,保存至e/extend/text/index.php,然后重新生成内容页面。
<?php
require(‘../../class/connect.php’); //引入数据库配置文件和公共函数文件
require(‘../../class/db_sql.php’); //引入数据库操作文件
require(‘../../data/dbcache/class.php’); //引入栏目缓存文件
$link=db_connect(); //连接MYSQL
$empire=new mysqlquery(); //声明数据库操作类
$editor=1; //声明目录层次

$lguserid=intval(getcvar(‘mluserid’));//登陆用户ID
$id=intval($_GET[id]);//文章ID
$classid=intval($_GET[classid]);//文章ID
$r=$empire->fetch1(“select * from {$dbtbpre}ecms_news_data_1 where id=’$id’ limit 1”);//获取附表文章内容
$s=$empire->fetch1(“select count(userid) as tool from {$dbtbpre}enewspl_1 where id=’$id’ and userid=’$lguserid’ and checked=’0′ limit 1”);//获取评论数

if($s[‘tool’]>0)
{
$newstext=stripslashes($r[‘newstext’]);
}
else
{
$newstext=esub(stripslashes($r[‘newstext’]),300);
}

$json_arr[] = array(
“id”=>$r[‘id’],
“newstext”=>$newstext
); //压入数组

$result=array(‘info’=>$json_arr);
$json=json_encode($result);
echo $json;
db_close(); //关闭MYSQL链接
$empire=null; //注消操作类变量
?>

订阅评论
提醒
guest的头像

0 评论
内联反馈
查看所有评论
0
希望看到您的想法,请您发表评论x