Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/261.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 WooCommerce评论短代码中的星星_Php_Woocommerce - Fatal编程技术网

Php WooCommerce评论短代码中的星星

Php WooCommerce评论短代码中的星星,php,woocommerce,Php,Woocommerce,我是一名自学成才的前端web开发人员,需要一些代码方面的帮助 我找到了一种方法,通过快捷码将随机评论添加到我正在使用的网站:。我已经编辑了该功能以适合我的客户网站 但是,我想显示星星以及标题和注释。我不知道怎么做。有人能帮忙吗 add_shortcode('woo_reviews', 'get_random_woo_reviews'); function get_random_woo_reviews( $atts ){ // Shortcode Attributes $atts = short

我是一名自学成才的前端web开发人员,需要一些代码方面的帮助

我找到了一种方法,通过快捷码将随机评论添加到我正在使用的网站:。我已经编辑了该功能以适合我的客户网站

但是,我想显示星星以及标题和注释。我不知道怎么做。有人能帮忙吗

add_shortcode('woo_reviews', 'get_random_woo_reviews');

function get_random_woo_reviews( $atts ){
// Shortcode Attributes
$atts = shortcode_atts( array(
    'limit' => '3', // <== Set to 3 reviews by default
), $atts, 'woo_reviews' );

global $wpdb;

// The SQL random query on product reviews
$comments = $wpdb->get_results( $wpdb->prepare("
    SELECT *
    FROM  {$wpdb->prefix}comments c
    INNER JOIN {$wpdb->prefix}posts p ON c.comment_post_ID = p.ID
    WHERE c.comment_type = 'review' AND p.post_status = 'publish'
    ORDER BY RAND() LIMIT %d
", intval( esc_attr($atts['limit']) ) ) );

ob_start(); // Start buffering

## CSS applied styles
?>
<style>
    ul.product-reviews, ul.product-reviews li { list-style: none; margin:0; padding:0px 24px 24px; line-height: normal;}
    ul.product-reviews li { display:block; max-width: 300px, padding: 10px; display:inline-block; vertical-align: text-top;}
    ul.product-reviews li .title {font-size: 16px; color: #F14500}
    ul.product-reviews li .content {max-width: 300px; font-size: 16px; margin-bottom: 6px;}
    ul.product-reviews li .author, ul.product-reviews li .date  {display: block; font-size: 16px; color: #F14500}
</style>
<?php

## HTML structure
?>
<ul class="product-reviews"><?php

foreach ( $comments as $comment ) {
    ?>
    <li>
        <h4 class="author"><?php printf( __(" %s") . ' ', '<strong>' . $comment->comment_author . '</strong>' ); ?></h4>
        <div class="content"><?php echo $comment->comment_content; ?></div>

    </li>
    <?php
}
?></ul><?php

return ob_get_clean(); // Return the buffered output
}

这个[链接]有用吗?请注意,忽略已被接受的答案,看看其他答案-不要试图自己直接调用sql。谢谢!我将研究各种解决方案,看看什么适合我的网站。后端代码就是这样一条学习曲线!