[英]Wordpress comments and ditching wp_list_comments()
称之为OCD或者只是强迫性地将逻辑与表示分开,但我讨厌关于wp_list_comments()的一切 - 并且在某种程度上,还讨论了comment_form() - 我想知道是否有人有一个好的循环评论的例子以前的方式。
我知道回调和那里的选项,但我也不喜欢该选项。
任何帮助或方向正确的方向表示赞赏。
干杯。
我写了一篇关于此的小帖子。 这里
有几种方法来提取信息,但我喜欢这样做...使用get_comments()函数,您可以构建大部分需要的东西。
<?php
$recent_comments = get_comments( array(
'number' => 5,
'status' => 'approve',
'type' => 'comment'
) );
?>
在$ recent_comments上执行print_r
<?php
echo "<pre>";
print_r($recent_comments);
echo "</pre>";
?>
[0] => stdClass Object
(
[comment_ID] => 23387
[comment_post_ID] => 32
[comment_author] => Marty
[comment_author_email] => myemail@myemail.com
[comment_author_url] => http://www.website.com
[comment_author_IP] => 11.111.11.111
[comment_date] => 2010-09-22 08:09:24
[comment_date_gmt] => 2010-09-22 07:09:24
[comment_content] => the content of the comment
[comment_karma] => 0
[comment_approved] => 1
[comment_agent] => Mozilla
[comment_type] =>
[comment_parent] => 0
[user_id] => 2
[comment_subscribe] => N
)
然后只需执行一个for循环来处理每个注释,并显示或隐藏您想要的内容..
<?php
foreach ($recent_comments as $comment)
{
?>
<li>
<a href="<?php echo get_permalink($comment->comment_post_ID);?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>">
<?php echo get_avatar( $comment->comment_author_email, '55' ); ?>
</a>
<h3>
<a href="<?php echo get_permalink($comment->comment_post_ID);?>#comment-<?php echo $comment->comment_ID;?>" title="<?php echo $comment->comment_author;?> on <?php echo get_the_title($comment->comment_post_ID); ?>">
<?php echo get_the_title($comment->comment_post_ID); ?>
</a>
</h3>
By: <?php echo $comment->comment_author;?>
</li>
<?php
}
?>
挂钩到get_avatar()函数,这将让你从那里的电子邮件地址生成一个图像,如果他们有...
<?php echo get_avatar( $comment->comment_author_email, '55' ); ?>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.