2011-02-14 56 views
0

称之为强迫症或迫切需要将逻辑与表示分开,但我讨厌关于wp_list_comments()的所有内容 - 以及在某种程度上,comment_form() - 我想知道是否任何人都有一个很好的例子来循环评论它以前的做法。WordPress的评论和开水wp_list_comments()

我知道那里的回调和我的选择,但我不喜欢那个选项。

任何帮助或正确的方向点赞赏。

干杯。

回答

2

我写了一篇关于此的小文章。 here

Theres有几种方式来拉动信息,但我喜欢这样做...... 使用get_comments()函数,你可以建立大多数你需要的东西。

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

上$做一个print_r的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] => [email protected] 
      [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'); ?>