2013-04-04 51 views
0

我使用的是Wordpress,並且在我的單個帖子頁面上我不想顯示對此特定帖子的所有評論,但是我的博客中的所有帖子都收到了所有評論。不應該$ post_id默認爲有問題的帖子?如果您在使用The Loop然後<?php comments_template('', true); ?>你不必通過POST_ID這將自動顯示特定職位的評論

$comments = get_comments(); 
foreach($comments as $comment) : 

    if ($comment->comment_approved == 1) { 

    echo '<hr /><h5>' . $comment->comment_author . ' 
    </h5><p class="visitorAuthor">' . $comment->comment_date . '</p> 
    <p>' . $comment->comment_content . '</p>'; 
    if ($comment->comment_author_url != '') { echo '<p><a href="' . $comment->comment_author_url . '" Target="_blank">Besök min hemsida</a>' ; } 

} 

endforeach; 

回答

1

:我有這樣的代碼。 comments_template

但是對於get_comments,您必須通過post_id參數才能獲取特定帖子的評論。 默認情況下它會得到所有的評論get_comments

<?php 
$args = array(
    'status' => 'approve', 
    'post_id' => 1, // use post_id, not post_ID 
); 
$comments = get_comments($args); 

上面的代碼應該得到所有帖子ID批准的評論1

+0

謝謝你讓我早上一個好:) – 2013-04-04 07:03:54

+0

高興我是 ;) :) – 2013-04-04 07:09:34