Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.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 我正在寻找一种方法来显示随机产品在产品类别页面使用woocomerce_Php_Wordpress - Fatal编程技术网

Php 我正在寻找一种方法来显示随机产品在产品类别页面使用woocomerce

Php 我正在寻找一种方法来显示随机产品在产品类别页面使用woocomerce,php,wordpress,Php,Wordpress,如何随机更改同一类别的产品?我一直在寻找,但似乎找不到任何插件/脚本来做这件事,有人有这个想法。。。谢谢您可以使用以下代码显示“CATXXX”的产品行: 您可以尝试使用此代码短代码 [product_category category="category_slug" per_page="10" orderby="rand"] Or <?php echo do_shortcode( '[product_category category="category_slug" per_page=

如何随机更改同一类别的产品?我一直在寻找,但似乎找不到任何插件/脚本来做这件事,有人有这个想法。。。谢谢

您可以使用以下代码显示“CATXXX”的产品行:


您可以尝试使用此代码短代码

[product_category category="category_slug" per_page="10" orderby="rand"]

Or

<?php echo do_shortcode( '[product_category category="category_slug" per_page="10" orderby="rand"]' ) ?>
[product\u category=“category\u slug”per\u page=“10”orderby=“rand”]
或

欢迎来到SO,在提问时请更具体一点:您尝试了什么,您期望什么,等等。请查看我的答案,这可能会对您有所帮助。
$args = array(
    'posts_per_page'   => 1,
    'orderby'          => 'rand',
    'category'         => 'CATXXX'
    'post_type'        => 'product'); 

$random_products = get_posts( $args );

foreach ( $random_products as $post ) : setup_postdata( $post ); ?>
    <li>
        <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    </li>
<?php endforeach; 
wp_reset_postdata();
[product_category category="category_slug" per_page="10" orderby="rand"]

Or

<?php echo do_shortcode( '[product_category category="category_slug" per_page="10" orderby="rand"]' ) ?>