ZblogPHP调用评论代码

在ZblogPHP中,调用评论列表通常使用内置的模板标签。以下是一个简单的例子,展示如何在文章页面调用评论列表:

<!-- 文章页面调用评论列表 -->
{foreach $comments as $comment}
  <div class="comment">
    <div class="comment-author">
      <img src="{$comment.Gravatar}" alt="头像" class="gravatar"/>
      <strong>{$comment.Author}</strong>
    </div>
    <div class="comment-content">
      {$comment.Content}
    </div>
    <div class="comment-info">
      <span class="comment-time">{$comment.Time('Y-m-d H:i')}</span>
      <!-- 如果需要显示评论管理链接,可以添加以下代码 -->
      {if $user.ID==$article.AuthorID || $user.ID==$comment.AuthorID}
        <a href="{@cp($comment.ID)}" title="{lang edit}">{lang reply}</a>
        <a href="{@delComment($comment.ID)}" title="{lang delete}">{lang delete}</a>
      {/if}
    </div>
  </div>
{/foreach}

在上面这个例子中,$comments 是一个包含评论信息的数组,通过 foreach 循环进行遍历。$comment 对象包含了评论的相关信息,如作者、内容、时间等。$comment.Gravatar 是用户的Gravatar头像链接,$comment.Author 是评论作者,$comment.Content 是评论内容,$comment.Time 是评论时间。 这个模板代码应该放在ZblogPHP的主题模板文件中,通常是放在 zb_users/theme/[your-theme]/article.php 文件中,在文章页面调用。 请注意,这个代码示例假设你已经有一个ZblogPHP的环境,并且你的主题已经启用了评论功能。如果你需要进一步定制,比如添加评论的回复层级或者处理特定的评论状态,你可能需要编写更复杂的逻辑代码。

除了以上在文章页面调用外,另外以下还提供了三种调用评论的方式,可以根据判断代码或者自己写CSS样式以达到自己想要的效果,当然了吗,也不仅限制在文章页面调用。

第一种:

{php}
$comments = $zbp->GetCommentList('*', array(array('=', 'comm_IsChecking', 0),array('<>', 'comm_AuthorID','1')), array('comm_PostTime' => 'DESC'), 10, null);
{/php}
{foreach $comments as $comment}
{php}$clpl = preg_replace('/\r\n\s+/', '', trim(SubStrUTF8(TransferHTML($comment->Content,'nohtml'),60)).'');{/php}<li>
<p>
<a href="{$comment.Post.Url}#cmt{$comment.ID}" target="\_blank">{$clpl}</a>
<small><span><img alt="{$comment.Author.Name}" src="{$comment.Author.Avatar}" ></span>{$comment.Author.Alias} 评论于:<a href="{$comment.Post.Url}#cmt{$comment.ID}" title="{$comment.Post.Title}" target="\_blank">{$comment.Post.Title}</a></small>
</p>
</li>
{/foreach}

第二种:

{php}
$comments = $zbp->GetCommentList('*', array(array('=', 'comm_IsChecking', 0)), array('comm_PostTime' => 'DESC'), 10, null);
$str = '';
{/php}
{foreach $comments as $comment}
{$comment.Author.Name}
{php}$intro= preg_replace('/[\r\n\s]+/', '', trim(SubStrUTF8(TransferHTML($article->Content,'[nohtml]'),150)).'...');{/php}{$intro}
{/foreach}

第三种:

{php}
$comments = $zbp->GetCommentList('*', array(array('=', 'comm_IsChecking', 0)), array('comm_PostTime' => 'DESC'), 10, null);
$str = '';
{/php}
{foreach $comments as $comment}
{$comment.Author.Name}:{$comment.Content} 
{/foreach}