我在一个网站上工作,一个客户想要显示一个随机的证明,在刷新时旋转。正在使用的推荐信只是人们留下的评论。所以我很好的提取了评论摘录,但我很难让它随机提取评论,它只是提取了最新的评论。有没有办法做到这一点?这是我使用的代码:
<?php
$args = array(
'status' => approve,
'number' => 1,
'orderby' => 'rand',
);
$comments = get_comments($args); ?>
<h3 class="side-heading">Customer Tesimonials</h3>
<div class="testimonials-inner">
<div class="testimonials-inner-inner">
<?php foreach ($comments as $comment) { ?>
<p><?php
$title = get_the_title($comment->comment_post_ID);
echo get_avatar( $comment, '53' );
//echo '<span class="recommauth">' . ($comment->comment_author) . '</span>';
?>"<?php
echo wp_html_excerpt( $comment->comment_content, 72 ); ?>"
</p>
<?php } ?>
<br />
<a class="re" href="/"><h4 class="butt-sub">Tell Your Story</h4></a>
</div>
</div>
</div>
</div>谢谢!
发布于 2011-11-22 06:47:41
orderby=rand不适用于WordPress评论,只适用于帖子。有关更多信息,请参阅下面的链接。
http://wordpress.org/support/topic/show-random-comment
发布于 2011-11-22 08:20:07
这不是经过测试的代码,而是类似下面这样的代码?
<?php
$args = array(
'status' => 'approve',
);
$all_comments = get_comments($args);
$random_key = array_rand($all_comments, 1);
$comments = array($all_comments[$random_key]); ?>https://stackoverflow.com/questions/8219352
复制相似问题