繁体   English   中英

WordPress评论

[英]Wordpress Comments

我正在一个网站上工作,当时一位客户希望显示随机的推荐信,该推荐信会在刷新时轮换显示。 所使用的推荐只是人们留下的评论。 没错,我几乎可以提取评论摘录,但是我很难获取它来提取随机评论,它只会提取最新的评论。 有没有办法做到这一点? 这是我正在使用的代码:

<?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>

谢谢!

orderby = rand不适用于WordPress注释,仅适用于帖子。 有关更多信息,请参见下面的链接。

http://wordpress.org/support/topic/show-random-comment

这不是经过测试的代码,而是类似的东西?

<?php 
    $args = array(
        'status' => 'approve',
    );

    $all_comments = get_comments($args);
    $random_key = array_rand($all_comments, 1);

    $comments = array($all_comments[$random_key]); ?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM