我正在使用"简单字段" wordpress的插件,并设置了一个上传文件的字段(在本例中为图像)。我使用以下代码,这将允许我在前端显示特定的图像/字段:
<?php
$selected_value = simple_fields_get_post_value(get_the_id(), array(1, 1), true);
$theImageURL = wp_get_attachment_url($selected_value);
echo '<img src="'.$theImageURL.'">';
?>
显然在这种情况下它使用该字段的特定键:_simple_fields_fieldGroupID_1_fieldID_1_numInSet_0
如何从帖子连接器显示多个图像,而无需专门识别每个字段。
如果我要将3个图像包含在帖子中,那么所有人都会使用数组(1,1)一个猜测ID只需要创建一个包含所有相关图像的数组
答案 0 :(得分:0)
自己搞清楚
<?php
$field_group_values = simple_fields_fieldgroup("cs_slider");
foreach ($field_group_values as $field_group_value) {
$theImageURL = wp_get_attachment_url($field_group_value);
echo '<img src="'.$theImageURL.'">';
}
?>
cs_slider是字段组的slug