Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/241.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress评论_Php_Wordpress - Fatal编程技术网

Php Wordpress评论

Php Wordpress评论,php,wordpress,Php,Wordpress,我在一个网站上工作,一个客户想显示一个随机的推荐,在刷新时轮换。使用的推荐信只是人们留下的评论。所以对,我几乎是在拉评论摘录,但我很难让它拉一个随机评论,它只是拉最新的。有办法做到这一点吗?这是我正在使用的代码: <?php $args = array( 'status' => approve, 'number' => 1, 'orderby' => 'rand', );

我在一个网站上工作,一个客户想显示一个随机的推荐,在刷新时轮换。使用的推荐信只是人们留下的评论。所以对,我几乎是在拉评论摘录,但我很难让它拉一个随机评论,它只是拉最新的。有办法做到这一点吗?这是我正在使用的代码:

<?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评论,仅适用于帖子。有关更多信息,请参阅下面的链接


这不是经过测试的代码,而是类似这样的代码

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

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

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

乍一看,代码看起来不错。尝试禁用插件。例如,众所周知,可湿性粉剂粘性会引起问题
order
的有效值仅为
ASC
DESC