首先使用PHPCMS的comment标签调用最新评论,通过{pc:comment action="get_comment_list"}获取数据并按时间倒序排列,再用{loop}循环输出每条评论内容。

在 PHPCMS 中调用最新评论列表,可以通过使用系统自带的标签或直接 SQL 查询来实现。以下是几种常用方法:
PHPCMS V9 提供了 {pc:content} 和 {pc:comment} 标签,但评论模块需启用。调用最新评论可使用 comment 模块的 get 标签:
{pc:comment action="get_comment_list" page="$page" siteid="$siteid" order="datetime DESC" num="10"}
{loop $data $val}
phpcnli>
<a href="{$val[url]}" target="_blank">{$val[title]}</a> - {$val[username]} 评论:
<span style="color:#666;">{str_cut($val[content],80)}</span>
</li>
{/loop}
{/pc}
如果标签不生效或需要更灵活控制,可以直接查询数据库表:
立即学习“PHP免费学习笔记(深入)”;
{pc:get sql="SELECT c.*, ct.title, ct.url FROM v9_comment_data_1 c LEFT JOIN v9_news ct ON c.contentid=ct.id WHERE c.siteid=1 ORDER BY c.datetime DESC" num="10"}
{loop $data $r}
<a href="{$r[url]}" target="_blank">{$r[title]}</a> - {$r[username]}
<p style="color:#999;">{date('Y-m-d H:i',$r[datetime])}: {str_cut($r[content],100)}</p>
</li>
{/loop}
{/pc}
基本上就这些方法,推荐优先使用 comment 标签方式,简洁安全。
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号