php - PHP函数按需
问题描述
我在 woocommerce 中有一个自定义选项卡,可以将备件循环到当前产品。在某些情况下,备件很多,产品需要很长时间才能加载。是否有一些聪明的方法可以“按需”加载标签内容,而不是每次显示产品时?选项卡内容是一个 wp-query 循环。
这是代码的一部分:
<?php
foreach( $categories as $category ):
$categoryID = $category->term_id;
$categoryName = $category->name;
//Query
// $argsParts = array(
// 'post_type' => 'product',
// 'tax_query' => array(
// array(
// 'taxonomy' => 'product_cat',
// 'terms' => $categoryID,
// 'operator' => 'IN',
// )
// ),
// 'meta_query' => array(
// array(
// 'key' => '_crosssell_ids',
// 'value' => $current_post_id,
// 'compare' => 'LIKE'
// )
// )
// );
$argsParts = array(
'post_type' => 'product',
'no_found_rows' => true,
'posts_per_page' => -1,
'post__in' => $crosssells,
'tax_query' => array(
array(
'taxonomy' => 'product_cat',
'terms' => $categoryID,
'operator' => 'IN',
)
),
);
$queryParts = new WP_Query($argsParts);
if($queryParts->have_posts()){
?>
<li class="g-acc-list__nav__button" id="g-acc-list__nav--<?php echo $categoryID ?>"><?php echo $categoryName ?></li>
<?php
}
endforeach;
解决方案
推荐阅读
- c++ - 在 CodeBlocks C++ 项目中遇到的此范围内未声明错误函数
- python - 在 matplotlib 中的 barplot 中指定条形之间的空格
- asp.net - 是否有 ASP.NET Web 表单的 Sustainsys.Saml2 示例
- python - Athena 查询失败并显示:“执行查询的权限不足”
- mobile - 如何做移动应用监控?
- javascript - 如何从 github 运行现有的节点应用程序?
- java - 在构造函数或类声明上注释 @Builder 有什么区别?(龙目岛)
- javascript - 使用网络蓝牙从 BLE 设备读取数据?
- java - 如何在springboot API中自定义@query的响应
- node.js - Rocket Chat - 文件上传堆栈为 0%