✨专业 WordPress 开发,定制建站,高效上线,合作即享优化服务!🚀

Blocksy WooCommerce 商品评论展示短代码


/* 基础布局 */
.ct-enhanced-reviews-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
    gap: 20px;
    margin: 2rem 0;
}

/* 评论卡片 */
.ct-review-card-enhanced {
    border: 1px solid var(--border-color, #e0e0e0);
    border-radius: 12px;
    overflow: hidden;
    background: #fff;
    box-shadow: 0 3px 10px rgba(0,0,0,0.03);
    transition: transform 0.3s ease, box-shadow 0.3s ease;
}

.ct-review-card-enhanced:hover {
    transform: translateY(-5px);
    box-shadow: 0 5px 15px rgba(0,0,0,0.1);
}

/* 商品信息头部 */
.ct-review-product-header {
    display: flex;
    padding: 20px;
    gap: 15px;
    border-bottom: 1px solid var(--border-color, #f0f0f0);
}

.ct-product-thumbnail {
    flex: 0 0 80px;
    border-radius: 8px;
    overflow: hidden;
    align-self: center;
}

.ct-product-thumbnail img {
    width: 100%;
    height: auto;
    display: block;
}

.ct-product-meta {
    flex: 1;
}

.ct-product-meta h4 {
    margin: 0 0 0px;
    font-size: 1rem;
    color: var(--heading-color, #333);
}

.ct-product-price {
    color: var(--accent-color, #3a7dfd);
    font-weight: 700;
    font-size: 1.1rem;

}

/* Blocksy主题星级评分 */


.ct-stars-rating .star-rating {
    --star-size: 14px;
    --star-color: var(--paletteColor2, #ffb900);
    display: inline-block;
    font-family: star;
    font-size: var(--star-size);
    line-height: 1;
    position: relative;
    width: 5.4em;
}

.ct-stars-rating .star-rating::before {
    content: "\53\53\53\53\53";
    color: var(--star-color);
    opacity: 0.25;
}

.ct-stars-rating .star-rating span {
    position: absolute;
    top: 0;
    left: 0;
    overflow: hidden;
}

.ct-stars-rating .star-rating span::before {
    content: "\53\53\53\53\53";
    color: var(--star-color);
}

/* 购买按钮 */
.ct-add-to-cart.button {
    display: inline-block;
    padding: 8px 16px;
    background: var(--button-color, #3a7dfd);
    color: #fff !important;
    border-radius: 4px;
    font-size: 0.9rem;
    text-decoration: none;
    transition: all 0.3s ease;
    border: none;
    cursor: pointer;
}

.ct-add-to-cart.button:hover {
    background: var(--button-hover-color, #2c6ae0);
    transform: translateY(-1px);
}

/* 评论内容区 */
.ct-review-body {
    padding: 20px;
}

.ct-reviewer-info {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    font-size: 0.9rem;
}

.ct-reviewer-name {
    font-weight: 600;
    color: var(--heading-color, #444);
}

.ct-review-date {
    color: var(--text-meta-color, #999);
}

.ct-review-text {
    line-height: 1.6;
    color: var(--text-color, #555);
    margin-bottom: 15px;
}

/* 图片画廊 */
.ct-review-gallery {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
    gap: 10px;
    margin-top: 15px;
}

.ct-gallery-item {
    border-radius: 6px;
    overflow: hidden;
    aspect-ratio: 1/1;
    transition: transform 0.3s ease;
}

.ct-gallery-item img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.ct-gallery-item:hover {
    transform: scale(1.05);
}

/* 无评论提示 */
.ct-no-reviews {
    text-align: center;
    color: var(--text-meta-color, #999);
    padding: 2rem;
}

/* 响应式设计 */
@media (max-width: 480px) {
    .ct-enhanced-reviews-grid {
        grid-template-columns: 1fr;
    }
    
   .ct-review-product-header {
        flex-direction: row;
        display: flex;
    }
    
    .ct-product-thumbnail {
        margin-bottom: 15px;
        width: 20%;
        flex: none;
    }
}
/**
 * Blocksy WooCommerce 商品评论展示短代码
 * 短代码: [product_reviews_with_images]
 */
add_shortcode('product_reviews_with_images', function($atts) {
    $atts = shortcode_atts([
        'limit'      => 4,
        'orderby'    => 'rating_desc',
        'show_image' => true,
        'show_price' => true,
        'show_button' => true
    ], $atts);

    // 查询参数
    $args = [
        'post_type'  => 'product',
        'status'     => 'approve',
        'number'     => intval($atts['limit']),
        'meta_query' => [['key' => 'rating', 'compare' => 'EXISTS']]
    ];

    // 排序逻辑
    switch ($atts['orderby']) {
        case 'newest':
            $args['orderby'] = 'comment_date_gmt';
            $args['order']   = 'DESC';
            break;
        case 'oldest':
            $args['orderby'] = 'comment_date_gmt';
            $args['order']   = 'ASC';
            break;
        case 'rating_asc':
            $args['meta_key'] = 'rating';
            $args['orderby']  = 'meta_value_num';
            $args['order']    = 'ASC';
            break;
        default: // rating_desc
            $args['meta_key'] = 'rating';
            $args['orderby']  = 'meta_value_num';
            $args['order']    = 'DESC';
    }

    $comments = get_comments($args);
    if (empty($comments)) return '<p class="ct-no-reviews">'.__('暂无商品评论', 'blocksy-companion').'</p>';

    ob_start();
    ?>
    <div class="ct-enhanced-reviews-grid">
        <?php foreach ($comments as $comment) : 
            $product = wc_get_product($comment->comment_post_ID);
            if (!$product) continue;
            
            $rating = intval(get_comment_meta($comment->comment_ID, 'rating', true));
            $images = get_comment_meta($comment->comment_ID, 'blocksy_comment_meta_images', true);
            ?>
            <div class="ct-review-card-enhanced">
                <!-- 商品信息区 -->
                <div class="ct-review-product-header">
                    <a href="<?php echo esc_url($product->get_permalink()); ?>" class="ct-product-thumbnail">
                        <?php echo $product->get_image('woocommerce_thumbnail'); ?>
                    </a>
                    <div class="ct-product-meta">
                        <h4><?php echo esc_html($product->get_name()); ?></h4>
                        
                        <?php if ($atts['show_price']) : ?>
                            <div class="ct-product-price"><?php echo $product->get_price_html(); ?></div>
                        <?php endif; ?>

                        <!-- Blocksy主题星级评分 -->
                        <div class="ct-stars-rating">
                            <?php 
                            echo blocksy_html_tag(
                                'div',
                                ['class' => 'star-rating'],
                                '<span style="width:'.($rating * 20).'%"></span>'
                            );
                            ?>
                        </div>
                        
                       
                    </div>
                </div>

                <!-- 评论内容区 -->
                <div class="ct-review-body">
                    <div class="ct-reviewer-info">
                        <span class="ct-reviewer-name"><?php echo esc_html($comment->comment_author); ?></span>
                        <span class="ct-review-date"><?php echo date_i18n('Y年m月d日', strtotime($comment->comment_date)); ?></span>
                    </div>
                    <div class="ct-review-text"><?php echo wpautop(esc_html($comment->comment_content)); ?></div>
                    
                    <?php if ($atts['show_image'] && !empty($images)) : ?>
                        <div class="ct-review-gallery">
                            <?php foreach ((array)$images as $image_id) : 
                                if (!wp_attachment_is_image($image_id)) continue;
                                $full_url = wp_get_attachment_image_url($image_id, 'full');
                                $thumb_url = wp_get_attachment_image_url($image_id, 'medium');
                                ?>
                                <a href="<?php echo esc_url($full_url); ?>" class="ct-gallery-item" data-fancybox="review-gallery-<?php echo $comment->comment_ID; ?>">
                                    <img src="<?php echo esc_url($thumb_url); ?>" alt="<?php esc_attr_e('用户评论图片', 'blocksy-companion'); ?>" loading="lazy">
                                </a>
                            <?php endforeach; ?>
                        </div>
                    <?php endif; ?>
                </div>
            </div>
        <?php endforeach; ?>
    </div>
    <?php
    return ob_get_clean();
});
55 2
55 2
WordPress 技术支持团队
WordPress 技术支持团队

💻 一位真诚且细致入微的年轻开发者🎓,专注于外贸网站定制开发领域。
🌟 专业承接 WordPress 建站设计定制与全方位开发服务。我们的独特优势在于,不仅精通网站开发技术,更将国际化主流美术设计元素🎨巧妙融合,同时制定精准有效的品牌营销策略📈。
💡 服务涵盖:
🔍WordPress 主题开发,打造独一无二的网站视觉风格与用户体验。
💻WordPress 网站定制,根据您的外贸业务需求,量身定制专属网站。
无论是网站架构搭建,还是界面美学设计,亦或是品牌推广策略,我们都能为您提供一站式的优质解决方案,助力您的外贸事业在互联网上脱颖而出,迈向全球市场🚀。

文章: 45

留下评论

您的邮箱地址不会被公开。 必填项已用 * 标注

提交您的请求

报价收集表

💥网站建设 | 实力说话,不搞虚的!

宝子们,咱就说,好多甲方都不乐意自己的网站被同行抄作业,这就跟你开个店,肯定不想让别人知道你的进货渠道是一个道理,对不?所以呢,为了给客户满满的安全感,咱网站上就没放任何客户案例作品的链接哈,这可是咱对客户隐私的保护。

📌但要是有真心想做网站的老板,或者宝子你只是想看看我们的案例,那就赶紧加我们网站的联系方式,咱麻溜地给你发几个瞅瞅,主打一个真诚!

要是你还没拿定主意要做啥风格的网站,也简单,你就找几个同行的网站发给我们,照着做就完事儿。咱选仿站可不代表没本事哈,只是咱实在受不了那种瞎扯犊子的无效沟通和繁琐到让人抓狂的流程。有些甲方做个企业展示型网站,非得找几十家供应商来卷,说实话,没真技术的公司才会在那跪舔甲方。咱不一样,咱就想踏踏实实地给客户做出性价比超高、让客户满意得直拍大腿的网站。那些跪舔的活儿,就让那些只会耍嘴皮子、没啥技术的公司去干吧,咱不伺候! #网站建设

#甲方乙方 #拒绝内卷

联系WordPress技术团队

我们期待您的来信。

提交您的请求

报价收集表