簡體   English   中英

Wordpress評論和放棄wp_list_comments()

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM