【发布时间】:2020-06-19 12:05:43
【问题描述】:
我想在产品类别的第三个产品(可能是第六个、第九个...)之后显示一些内容。并非每个类别都有额外的内容或相同数量的内容。所以它应该是灵活的。
我发现an example 使用以下代码:
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
<?php get_template_part( 'template-parts/content' ); ?>
<?php if ( $wp_query->current_post == 1 ) { ?>
<div>Put Ad Here</div>
<?php } ?>
<?php endwhile; endif; ?>
我将该代码添加到我的archive-product.php 中,如下所示:
if ( wc_get_loop_prop( 'total' ) ) {
while ( have_posts() ) {
the_post();
/**
* Hook: woocommerce_shop_loop.
*/
do_action( 'woocommerce_shop_loop' );
wc_get_template_part( 'content', 'product' );
if ( $wp_query->current_post == 1 ) {
echo '<div>Put Ad Here</div>';
}
}
}
但它没有显示任何内容。 如果有一种方法可以在不接触模板文件的情况下添加这些内容,那就太好了。
有没有我可以使用的钩子?
【问题讨论】:
标签: php wordpress woocommerce categories product