【问题标题】:Show multiple images/fields using the Simple Fields plugin for wordpress使用 wordpress 的简单字段插件显示多个图像/字段
【发布时间】:2014-03-17 17:06:49
【问题描述】:

我正在使用 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 只需要创建所有相关图像的数组

【问题讨论】:

    标签: php wordpress custom-fields


    【解决方案1】:

    这是我自己想出来的

    <?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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多