我想獲得WooCommerce中的所有產品並製作帶有主題的滑塊。無法獲得WooCommerce中的所有產品
所以我在function.php
代碼:
function zf_theme_home_slide() {
$args = array(
'post_type' => 'product', /* post type */
'post_status' => 'publish', /* post montasher shode */
'orderby' => 'date', /* moratab sazi bar asas tarikh — date , ID , author , type , name , title , parent , rand , comment_count — */
'order' => 'DESC' /* moratabsazi Soudi ya nozooli — DESK = Nozooli , ASC = Soudi */
);
$post_query = new WP_Query($args);
ob_start();
var_dump($post_query);
if($post_query->have_posts()) :
?>
<div class="flexslider" >
<ul class="slides">
<?php while ($post_query->have_posts()) :
$post_query->the_post();
// if(get_field('slide_hn_theme')){
$hn_permalink = get_the_permalink();
$hn_title = get_the_title();
$hn_thumbnail = get_the_post_thumbnail_url();
?>
<li class="product-thumbnail-outer">
<div>
<a class="slide_item" href=" <?php echo $hn_permalink ?> "><img width="300" height="140" src=" <?php echo $hn_thumbnail ?> " />
<span class="slide_items_details">
<span class="slide_item_title"><?php echo $hn_title ?> </span>
<span class="slide_item_creat"> <?php echo $hn_webcreate ?> </span>
</span>
</a>
</div>
</li>
<?php
// }
endwhile;
?>
</ul>
</div>
<?php
endif;
wp_reset_postdata();
return ob_get_clean();
}
add_shortcode('zf_theme_home_slide','zf_theme_home_slide'); /* pro_Des Copy to Page for Show Blogs */
但我只得到三種產品。我不知道爲什麼我的代碼只返回所有產品的三種產品。我該如何解決它?
加'回聲「
」的輸出;'有問題,還請確保您有更多的產品發佈比3。 – Noman添加arg'posts_per_page'=> -1 –
我使用了var_dump($ post_query);並且只顯示3歷時產品 –