[英]get_comments() in wordpress ignore the post_id passed to it
I am trying fit wordpress into my website, and instead of creating a theme, I am just making use of the APIs to put the blogs onto my website. 我正在尝试将wordpress放入我的网站中,而不是创建主题,而是使用API将博客放到我的网站上。 I am stuck with getting comments. 我一直在发表评论。 When I call$comments = get_comments(array('post_id=>'.$post->ID,'order' => 'ASC')); 当我调用$ comments = get_comments(array('post_id =>'。$ post-> ID,'order'=>'ASC')); I get comments for all posts. 我收到所有帖子的评论。 I am not a PHP developer, I am just learning now. 我不是PHP开发人员,我现在正在学习。 I am a java developer actually.. Anyway here's the code that doesnt work: 我实际上是一个Java开发人员。无论如何,这是不起作用的代码:
<?php global $more;
$more = -1;
$posts = get_posts('numberposts=10&order=ASC');
$counter=0;
foreach ($posts as $post) {
setup_postdata($post);?>
<div class="article">
<h2><?php the_title(); ?></h2>
<div class="clr"></div>
<h3><?php the_time('F j, Y'); ?></h3>
<div id="content<?php echo $counter; ?>" class="section sectionborder">
<?php the_content(); ?>
<h2>Post ID:<?php echo $post->ID?></h2>
/**
* This is where I call get_comments and the post is being passed
* correctly to it. Since the post ID is printed correctly above. But
* I am getting comments not related to this post as well
*/
<?php
$comments = get_comments(array('post_id=>'.$post->ID,'order' => 'ASC'));
echo '<h3>Comments</h3>';
foreach($comments as $comment) :
echo('<div class="comment">'
.$comment->comment_content.
'<span class="comment-author">-'. $comment->comment_author. '</span>
<span class="comment-date">'.date('Y-m-d H:i', strtotime($comment->comment_date)) .'</span>
</div>');
endforeach;
?>
</div>
<div id="a<?php echo $counter; ?>">
<a href="#">Read More</a>
</div>
</div>
<br/>
<hr/>
<?php $counter++; ?>
<?php } ?>
I don't know about wordpress, but you have an error here which could cause that problem: 我不了解wordpress,但是您在这里遇到一个错误,可能会导致该问题:
array('post_id=>'.$post->ID,'order' => 'ASC')
Should be: 应该:
array('post_id' => $post->ID, 'order' => 'ASC')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.