简体   繁体   中英

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.

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.

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

Do a print_r on $recent_comments

<?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..

<?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...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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