【发布时间】:2019-10-14 04:05:43
【问题描述】:
我按照 ACF 库页面 https://www.advancedcustomfields.com/resources/gallery/ 中的说明使用简码创建原生 Wordpress 库并从 ACF 库字段中的数据动态填充项目 ID。
示例:
编辑:我稍微修改了代码以包含$image_ids的定义
<?php
// Load value (array of ids).
$images = get_field('product_images');
$image_ids = get_field('product_images', false, false);
if( $images ) {
// Generate string of ids ("123,456,789").
$images_string = implode( ',', $image_ids );
// Generate and do shortcode.
$shortcode = sprintf( '', $images_string );
echo do_shortcode( $shortcode );
}
现在我的问题是返回一个错误,指出 $image_ids 的值未定义,因此根本看不到定义的位置。
我有一些以前使用的旧代码:
<?php
// different product sizes (gallery)
if(get_field('product_images')) : ?>
<h3>Product Images</h3>
<?php
$image_ids = get_field('product_images', false, false);
$shortcode = '[' . 'gallery ids="' . implode(',', $image_ids) . '"]';
echo do_shortcode( $shortcode );
endif;
?>
此代码确实有效,但返回错误php notice array to string conversion in jetpack-carousel。是的,我正在使用“Tiled Galleries Carousel without Jetpack”插件。
我真的很想遵循 ACF 文档中推荐的方法,但它对我不起作用。我做错了什么?
【问题讨论】:
-
我现在可以看到 $image_ids 是从
$image_ids = get_field('product_images', false, false);派生的。错误已消失,但未显示任何图片库。
标签: php wordpress advanced-custom-fields