- Web制作
Welcart 商品売れ筋ランキングを表示する

Welcart 専用ウィジェットで「Welcart ベストセラー」ってのもありますが、表示のカスタマイズ方法がなかなか見つからず。。
そこで色々と調べながら試行錯誤してみました。
この書き方だと特定のカテゴリー内の中での売れ筋ランキングっていうのもできて便利です。
<?php
global $usces;
$ids = $usces->get_bestseller_ids(999); //999は集計日数
$args = array(
'posts_per_page' => 5,
'category__in' => 13, //特定のカテゴリーで絞り込みする場合
'post__in' => $ids, //売れ筋商品
'orderby' => 'post__in'
);
$products = new WP_Query($args);
while ($products->have_posts()) : $products->the_post(); ?>
<?php
usces_the_item();
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
<a href="<?php the_permalink() ?>">
<div class="item__img">
<?php
$imgURL = usces_the_itemImageURL(0, $out = 'return');
if ($imgURL) : ?>
<?php usces_the_itemImage(0, 500, 500, $post); ?>
<?php else : ?>
<img src="<?php echo get_template_directory_uri(); ?>/assets/images/common/noimage.png" alt="" />
<?php endif; ?>
</div>
<div class="item__name"><?php usces_the_itemName(); ?></div>
<div class="item__price-set">
<div class="price"><?php usces_the_itemPrice(); ?></div>
<div class="unit">円</div>
</div>
</a>
</div>
<?php endwhile; ?>
<?php wp_reset_postdata(); ?>

名古屋の Web 制作会社で 9 年半働いた後フリーランスに。中小企業のWEBサイト制作実績 120 サイト以上。ディレクション、デザイン、コーディング、WordPress 構築まで手掛けます。Web制作に関わる情報やワーケーション日記などを執筆しています。