【问题标题】:Featured Product On Woo Commerce 3.0Woocommerce 3.0 上的特色产品
【发布时间】:2018-05-26 02:10:09
【问题描述】:

我是 WordPress 和编辑 StoreFront Woo Commerce 主题的新手,我有代码但不知道放在哪里,每个人都给出了答案,但没有提及更改文件的位置,请帮助!

    <ul class="products">
<?php
    $args = array(
        'post_type' => 'product',
        'posts_per_page' => 12,
        'tax_query' => array(
                array(
                    'taxonomy' => 'product_visibility',
                    'field'    => 'name',
                    'terms'    => 'featured',
                ),
            ),
        );
    $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 __( 'No products found' );
    }
    wp_reset_postdata();
?>

【问题讨论】:

    标签: php wordpress woocommerce storefront


    【解决方案1】:

    改变 WordPress 和插件功能方式的代码通常放在主题的 functions.php 文件中。 &lt;ul class="products"&gt; 是直接的 HTML,不应放在该文件中,除非它被处理为某种回显或打印输出。

    由于大多数主题都会在某个时候更新,因此您应该使用child theme 进行修改。

    【讨论】:

      猜你喜欢
      • 2013-02-22
      • 1970-01-01
      • 2018-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2018-02-25
      相关资源
      最近更新 更多