【发布时间】:2015-09-17 13:11:18
【问题描述】:
我正在使用自定义查询加载产品(这是它的代码)
/* Load The Beast Balls Category */
$args = array(
'post_type' => 'product',
'posts_per_page' => 100,
'product_cat' => 'beast-balls',
//'orderby' => 'date',
//'order' => 'desc'
);
$loop = new WP_Query( $args );
if ( $loop->have_posts() ) {
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div class="product-node cat-beast-balls" id="cat-beast-balls">
<?php wc_get_template_part( 'content', 'single-product' ); ?>
</div>
<?php endwhile;
}
wp_reset_postdata();
我的问题是查询会抓取所有产品,一旦完成,它会将它们转储到页面中。
有没有办法让它们在加载时一个一个地转储到页面中,这样看起来就好像它们加载得更快?
【问题讨论】:
-
您的意思是通过 AJAX 加载它们?关于这个话题有很多答案。
-
嗨 Dingo_d 我现在实际上是通过 AJAX 加载它们。你能帮我找到其中一些答案吗?我好像找不到他们!
-
PHP 正在缓冲输出,请尝试在循环中的
</div>之后使用flush(),这应该会有所帮助。 -
或者,您可以使用transient api 来缓存查询结果。但是你为什么要在循环之外查询 100 种产品呢?为什么不只查看野兽球的术语存档?或者利用分页和延迟加载。
标签: php wordpress optimization woocommerce