[英]How to make woocommerce products columns for custom shop page
我正在尋找WP_Query()
的列參數。 因為帖子類型將是product
。 請看下面的代碼:
$args = array(
'post_type' => 'product',
'posts_per_page' => 8,
'columns' => 3, // Can we have something like this
);
$loop = new \WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post();
wc_get_template_part( 'content', 'product' );
endwhile;
} else {
echo esc_html__( 'No products found', 'theme_core' );
}
wp_reset_postdata();
我們可以有一個列參數來獲取每行的產品嗎?
為此,您必須將 3 種產品的行放在下面的代碼中。
$args = array(
'post_type' => 'product',
'posts_per_page' => 8
);
$product = 1;
$total_product = get_products_count(); // Total Product
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) { ?>
<div class="row">
<?php while ( $loop->have_posts() ) : $loop->the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php if( $product % 3 == 0 ) { ?>
</div>
<?php } else { ?>
<?php if( $product == $total_product ) { ?>
</div>
<?php } ?>
<?php } ?>
<?php endwhile; $product++;
} else {
echo esc_html__( 'No products found', 'theme_core' );
}
wp_reset_postdata();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.