Php Woocommerce产品归档合并
我想将一些自定义字段项注入woocommerce产品归档页面(基于类别)。一个例子是:在所有项链的存档页面上,我想显示项链链接的网格以及一些支持图像(戴项链的模特等),这些图像可以在阵列中的任意点注入,但它们不一定是链接 我已经成功地拉入了我想要的图像,尽管它们目前在一个单独的数组中,并且在循环之前分组在页面顶部。那么,如何合并woocommerce产品循环数组和自定义图像数组呢 我正在抓取我在Php Woocommerce产品归档合并,php,arrays,wordpress,woocommerce,Php,Arrays,Wordpress,Woocommerce,我想将一些自定义字段项注入woocommerce产品归档页面(基于类别)。一个例子是:在所有项链的存档页面上,我想显示项链链接的网格以及一些支持图像(戴项链的模特等),这些图像可以在阵列中的任意点注入,但它们不一定是链接 我已经成功地拉入了我想要的图像,尽管它们目前在一个单独的数组中,并且在循环之前分组在页面顶部。那么,如何合并woocommerce产品循环数组和自定义图像数组呢 我正在抓取我在存档产品.php顶部设置的自定义字段: // Get ACF Image Repeater $quer
存档产品.php顶部设置的自定义字段:
// Get ACF Image Repeater
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$modelimages = get_field('model_images', $taxonomy . '_' . $term_id);
// If there are model images for the this product category
if($modelimages):
// Create empty model image array
$models = array();
while( have_rows('model_images', $taxonomy . '_' . $term_id) ): the_row();
// Add URLs of model pix to the array
$models[] = get_sub_field('file')['sizes']['medium'];
endwhile;
endif;
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
上面只是创建了一个图像URL数组,工作正常。我想在archive product.php
中的woocommerce产品循环中随机地“注入”每个项目:
// Get ACF Image Repeater
$queried_object = get_queried_object();
$taxonomy = $queried_object->taxonomy;
$term_id = $queried_object->term_id;
$modelimages = get_field('model_images', $taxonomy . '_' . $term_id);
// If there are model images for the this product category
if($modelimages):
// Create empty model image array
$models = array();
while( have_rows('model_images', $taxonomy . '_' . $term_id) ): the_row();
// Add URLs of model pix to the array
$models[] = get_sub_field('file')['sizes']['medium'];
endwhile;
endif;
<?php woocommerce_product_loop_start(); ?>
<?php woocommerce_product_subcategories(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php wc_get_template_part( 'content', 'product' ); ?>
<?php endwhile; // end of the loop. ?>
<?php woocommerce_product_loop_end(); ?>
它可能有各种各样的丑陋,但至少它起作用了。欢迎使用。在这里发布您尝试的代码中遇到卡住或遇到意外行为的部分被认为是礼貌的。你可以考虑编辑你的问题,并对你所尝试的内容做一些更详细的说明。对不起,Pavdidv,这个新的东西,所以不知道礼仪。“如何询问[…]提供详细信息。共享您的研究。”如果您不修改查询本身,我认为您可能会遇到分页问题。如果模型图像没有链接到任何东西,我可能会找到一种方法来为媒体库图像(我确信存在)分配术语。然后,您可以过滤pre\u get\u posts
,可能会将媒体图像添加到查询中。尽管我承认,由于WooCommerce中正在进行的自定义操作,而不是WordPress中无法完成的操作,我已经很难让WooCommerce商店查询与其他产品类型合并。