我希望获得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 */
但我只买三件产品。我不知道为什么我的代码只返回所有产品的三种产品。我该如何解决?
答案 0 :(得分:0)
尝试使用以下代码,您只需要为每页限制添加帖子。
$args = array(
'post_type' => 'product', /* post type */
'post_status' => 'publish',
'orderby' => 'date',
'posts_per_page' => -1,
'order' => 'DESC'
);