【问题标题】:How to make woocommerce products columns for custom shop page如何为自定义商店页面制作 woocommerce 产品列
【发布时间】:2020-11-17 14:35:51
【问题描述】:

我正在寻找 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();

我们可以有一个列参数来获取每行的产品吗?

【问题讨论】:

  • 你能澄清一下这个问题吗,在这里很难确定你在问什么

标签: php wordpress woocommerce


【解决方案1】:

为此,您必须像下面的代码一样放置 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();

【讨论】:

  • 它抛出未定义的函数get_products_count().
猜你喜欢
  • 2019-03-05
  • 2014-05-27
  • 1970-01-01
  • 1970-01-01
  • 2017-10-09
  • 2015-04-13
  • 1970-01-01
  • 1970-01-01
  • 2016-09-21
相关资源
最近更新 更多