[英]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.