ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
产品和文章的简易调用: ``` <?php $query = new WP_Query( array( // 'post_type' => 'post', 'post_type' => 'product', 'posts_per_page' => '5', 'order' => 'desc', // 最新 - asc,最早 - desc )); if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();?> <!-- 内容 --> <?php endwhile; ?> <?php else : echo '<p>没有内容</p>'; endif; ?> ``` 产品的详细调用: ``` <?php global $wp_query, $post, $woocommerce,$query_string; $args = array( 'tax_query' => array( 'relation' => 'OR', array( 'taxonomy' => 'product_cat', // 此处参数指定为产品目录 'field' => 'id', // 调用依据为产品目录id 'terms' => array( 20 ), // 20为产品目录id ), ), 'posts_per_page' => 5, // 一共需要调用的文章数量 'post_status' => 'publish', // 调用的文章为已经发布 'post_type' => 'product', // 调用的类型为产品(product) 'no_found_rows' => 1, 'order' => 'desc', // 最新 - asc,最早 - desc 'meta_query' => array() // 还可以使用post meta进行查询,这个和wordpress循环中使用一样 ); //以上为循环的参数 $query= new WP_Query( apply_filters( 'woocommerce_products_widget_query_args', $args ) );//建立循环查询 //开始循环 if($query->have_posts()) : while ( $query->have_posts() ) :$query->the_post(); ?> <!-- 内容 --> <?php endwhile; // 结束循环 wp_reset_query(); // 清除循环 endif; ?> ``` 123