我正在使用get_comments()
来检索我自定义主题中特定wordpress帖子的评论。问题是输出中没有HTML。
例如,当用户向评论添加URL时,在管理控制台中它显示为链接,但使用get_comments()
时,它仅返回文本。
由于在此页面上没有过滤器或其他选项可以解决此问题:http://codex.wordpress.org/Function_Reference/get_comments我不太清楚这是怎么回事。我以后应该用javascript管理吗?
感谢您的帮助!
我想您可以应用'the_content'过滤器;
<?php foreach (get_comments() as $comment): ?>
<div class="comment">
<?=apply_filters('the_content', $comment->comment_content) ?>
</div>
<?php endforeach; ?>
我建议您查看现有主题的comments.php
模板文件,对其进行修改以适合您的目的,然后通过comments_template()
对其进行调用。
基于ZURB基础框架的主题,for example使用wp_list_comments
:
<ol class="commentlist">
<?php wp_list_comments(); ?>
</ol>
看看是否能给您更多格式化的输出。
您可以使用它,它将显示用户名,日期,头像及其所有p标签。
<div class="comments">
<?php $comments_args = array(
// change the title of send button
'label_submit'=>'Send',
// change the title of the reply section
'title_reply'=>'Write a new comment',
// remove "Text or HTML to be displayed after the set of comment fields"
'comment_notes_after' => '',
// redefine your own textarea (the comment body)
'comment_field' => '<p class="comment-form-comment"><textarea id="comment" name="comment" aria-required="true" placeholder="Type your comment"></textarea></p>',
);
comment_form($comments_args); ?>
</div>
<div class="comments-form">
<?php
$user_id = get_current_user_id();
$user_specific_comments = get_comments(
array(
'post_id' => YOUR_POST_ID,
)
);
wp_list_comments(
array(
'per_page' => 10,
),
$user_specific_comments
);
?>
</div>