Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/263.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php wordpress-在旋转木马中提供产品的自定义主页_Php_Wordpress_Wordpress Theming_Woocommerce - Fatal编程技术网

Php wordpress-在旋转木马中提供产品的自定义主页

Php wordpress-在旋转木马中提供产品的自定义主页,php,wordpress,wordpress-theming,woocommerce,Php,Wordpress,Wordpress Theming,Woocommerce,我正在用WooCommerce建立一个网店 我做了一个自定义主页。在这个主页上,我想以类似旋转木马的结构(每个视图3个)显示每个类别的产品。但是如何将数据(每个类别的产品)放入我自己的自定义主页?要清楚,此主页位于产品概述(或“archive product.php”)之前 谢谢 源代码稍微修改: 您将需要使用以下内容: <ul class="products"> <?php // Change product_cat to the slug of th

我正在用WooCommerce建立一个网店

我做了一个自定义主页。在这个主页上,我想以类似旋转木马的结构(每个视图3个)显示每个类别的产品。但是如何将数据(每个类别的产品)放入我自己的自定义主页?要清楚,此主页位于产品概述(或“archive product.php”)之前


谢谢

源代码稍微修改:

您将需要使用以下内容:

<ul class="products">
    <?php
        // Change product_cat to the slug of the category you want
        $args = array( 'post_type' => 'product', 'posts_per_page' => 1, 'product_cat' => 'shoes', 'orderby' => 'rand' );
        $loop = new WP_Query( $args );
        while ( $loop->have_posts() ) : $loop->the_post(); global $product; ?>

            <h2>Shoes</h2>

                <li class="product">    

                    <a href="<?php echo get_permalink( $loop->post->ID ) ?>" title="<?php echo esc_attr($loop->post->post_title ? $loop->post->post_title : $loop->post->ID); ?>">

                        <?php if (has_post_thumbnail( $loop->post->ID )) echo get_the_post_thumbnail($loop->post->ID, 'shop_catalog'); else echo '<img src="'.woocommerce_placeholder_img_src().'" alt="Placeholder" width="300px" height="300px" />'; ?>

                        <h3><?php the_title(); ?></h3>

                        <span class="price"><?php echo $product->get_price_html(); ?></span>                    

                    </a>

                    <?php woocommerce_template_loop_add_to_cart( $loop->post, $product ); ?>

                </li>

    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
</ul><!--/.products-->

您只需将产品类别更改为您想要的类别,并将每页帖子设置为3即可。

谢谢,它可以工作了!现在,如果我想为每个可用类别循环此ul,该怎么办?您可以使用
get_post_types(array(''u builtin'=>false))
来获取所有自定义post类型,然后使用
foreach
循环来循环它们。这就是我得到的反馈:acf产品产品、变体商店、订单商店、耦合我是否应该修改“内置”以获得其中的类别或…?对不起,我误解了你的意思。对于类别,您可以创建所需类别的数组,然后循环遍历它们:
$categories=array('cat1','cat2','shoes','shirts');foreach($categories as$category){$args=array('post_type'=>'product','posts_per_page'=>1,'product_cat'=>$category,'orderby'=>'rand');//继续代码的其余部分}