简体   繁体   English

Wordpress评论和放弃wp_list_comments()

[英]Wordpress comments and ditching wp_list_comments()

Call it OCD or an just obsessive need to separate logic from presentation, but I hate everything about wp_list_comments() — and to an extent, comment_form() — and I'd like to know if anyone has a good example of looping through comments the way it used to be done. 称之为OCD或者只是强迫性地将逻辑与表示分开,但我讨厌关于wp_list_comments()的一切 - 并且在某种程度上,还讨论了comment_form() - 我想知道是否有人有一个好的循环评论的例子以前的方式。

I am aware of the callback and my options there, but I don't fancy that option either. 我知道回调和那里的选项,但我也不喜欢该选项。

Any help or a point in the right direction is appreciated. 任何帮助或方向正确的方向表示赞赏。

Cheers. 干杯。

Ive written a small post about this. 我写了一篇关于此的小帖子。 here 这里

Theres a few ways to pull the info, but i like doing this... using the get_comments() function you can build up mostly what your needing. 有几种方法来提取信息,但我喜欢这样做...使用get_comments()函数,您可以构建大部分需要的东西。

<?php
$recent_comments = get_comments( array(
  'number'    => 5,
  'status'    => 'approve',
  'type'    => 'comment'
) );
?>

Do a print_r on $recent_comments 在$ 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
        )

Then just do a for loop to work through each comment and show or hide what you want.. 然后只需执行一个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
}
?>

hooking into the get_avatar() function, this will let you generate an image from there email address, if they have one... 挂钩到get_avatar()函数,这将让你从那里的电子邮件地址生成一个图像,如果他们有...

<?php echo get_avatar( $comment->comment_author_email, '55' ); ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM