Php 在星级旁边显示商业评论计数

Php 在星级旁边显示商业评论计数,php,wordpress,woocommerce,Php,Wordpress,Woocommerce,Woocommerce明星评级,无评论计数 修改了Woocommerce的星级评分和评论计数 Woocommerce已经在单个产品页面中的星级旁边显示评论计数。但在商店和档案页面上,它只显示星级。按照以下步骤显示星级计数,即使在商店和档案页面上也是如此 步骤1)在主题的根目录中创建一个新文件夹,并将其命名为“woocommerce” 步骤2)在新创建的“woocommerce”文件夹中创建一个新文件夹,并将其命名为“loop” 步骤3)将“rating.php”文件添加到新创建的“loop”文

Woocommerce明星评级,无评论计数

修改了Woocommerce的星级评分和评论计数


Woocommerce已经在单个产品页面中的星级旁边显示评论计数。但在商店和档案页面上,它只显示星级。按照以下步骤显示星级计数,即使在商店和档案页面上也是如此

步骤1)在主题的根目录中创建一个新文件夹,并将其命名为“woocommerce”

步骤2)在新创建的“woocommerce”文件夹中创建一个新文件夹,并将其命名为“loop”

步骤3)将“rating.php”文件添加到新创建的“loop”文件夹中

现在你的目录看起来像这样

/public_html/wp content/themes/YOUR-THEME/woocommerce/loop

将下面的代码添加到新创建的“rating.php”中,并根据需要进行自定义

<?php
/**
 * Loop Rating
 *
 * This template can be overridden by copying it to yourtheme/woocommerce/loop/rating.php.
 *
 * HOWEVER, on occasion WooCommerce will need to update template files and you
 * (the theme developer) will need to copy the new files to your theme to
 * maintain compatibility. We try to do this as little as possible, but it does
 * happen. When this occurs the version of the template file will be bumped and
 * the readme will list any important changes.
 *
 * @see         https://docs.woocommerce.com/document/template-structure/
 * @author      WooThemes
 * @package     WooCommerce/Templates
 * @version     3.0.0
 */

if ( ! defined( 'ABSPATH' ) ) {
    exit;
}

global $product;

if ( get_option( 'woocommerce_enable_review_rating' ) === 'no' ) {
    return;
}

$rating_count = $product->get_rating_count();
$review_count = $product->get_review_count();
$average      = $product->get_average_rating();

if ( $rating_count >= 0 ) : ?>

            <?php echo wc_get_rating_html($average, $rating_count); ?>
        <?php if ( comments_open() ): ?><a href="<?php echo get_permalink() ?>#reviews" class="woocommerce-review-link" rel="nofollow">(<?php printf( _n( '%s',$review_count,'woocommerce' ), '<span class="count">' . esc_html( $review_count ) . '</span>' ); ?>)</a><?php endif ?>


<?php endif; ?>

以防这不起作用

在“woocommerce”文件夹中添加“templates”文件夹,然后在“templates”文件夹中添加“loop”文件夹

现在目录看起来像这样

/public_html/wp content/themes/YOUR-THEME/woocommerce/templates/loop


从理论上讲,这将是完美的,但我认为说明缺少一个步骤来调用评论计数,因为我尝试了两种方法,没有显示评论计数,只有星星

将循环文件夹移动到woocommerce活动主题中似乎解决了计数问题,但我希望它位于星星旁边,而不是下方。我该如何解决这个问题


您能告诉我如何将评论计数编号输入twc woocommerce插件文件,以便其显示每个产品的总评论编号吗