【发布时间】:2017-08-28 15:39:23
【问题描述】:
我正在尝试提取随机产品缩略图以在我的一个页面上显示为图像。我似乎找不到可行的方法,并尝试了 this 和 this 帖子中的解决方案。
在 div 中回显它也是有益的。
这是我目前正在尝试的,但我仍然不确定如何做到这一点。
functions.php:
function get_random_thumbnails_for_reg(){
if(is_page(381)){
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'field' => 'slug',
'terms' => 'allison-1000-gm-duramax-series'
)
)
);
$random_products = get_posts( $args );
foreach ( $random_products as $post ) : setup_postdata( $post );
?>
<div id="randomPic"><a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a></div>
<?php
endforeach;
wp_reset_postdata();
}
}
add_action('wp_footer', 'get_random_thumbnails_for_reg', 50);
【问题讨论】:
标签: php wordpress woocommerce categories product