php - 在 WooCommerce 类别档案中仅在第 6 个产品之后插入一次 DIV
问题描述
我想在一个产品类别的第五个产品之后显示一些内容。
基于在 WooCommerce 存档答案代码中的产品行之间添加内容,我正在使用这个稍微修改过的版本代码:
add_action( 'woocommerce_shop_loop', 'action_woocommerce_shop_loop', 100 );
function action_woocommerce_shop_loop() {
// Only on producy cayegory archives
if ( is_product_category() ) :
global $wp_query;
// Get the number of columns set for this query
$columns = esc_attr( wc_get_loop_prop( 'columns' ) );
// Get the current post count
$current_post = $wp_query->current_post;
if ( ( $current_post % $columns ) == 0 && $current_post%6==0 ) :
?>
<div class="product-grid-item col-md-3 col-sm-4 col-xs-6"><div class="banner"><?php _e("Custom content here"); ?></div></div>
<?php
endif; endif;
}
这种工作,但多次添加自定义内容(DIV)。它每 6 列添加一次。在第 6 列之后,我只需要一个 DIV。
解决方案
如果您想在第六列之后只显示一次内容,只需将 if 条件更改为:
if ($current_post == 6) :
推荐阅读
- docker - 为什么我无法连接到 Redis Docker 组件的端口?
- bash - Rundeck debconf-set-selection:
- xslt - 如何在 XSLT 中创建 JS 对象字面量并传递给 JS 方法
- asp.net - 如果版本号为零,Nuget 包还原将跳过版本号的修订部分
- javascript - 如何将宽度应用于css flexbox
- c# - 将 Appsettings.json (.core) 中的 url 参数传递给 React
- vue.js - 如何在 vuetify 中更改 svg 的高度宽度?
- laravel - 如何在控制器的关系方法中应用条件?
- amazon-web-services - 如何将 AWS s3 与 Docker 连接起来
- iis - 如何在 web.config 中实现 {REQUEST_FILENAME} - httpErrors