将附件上载到帖子/页面时,它们将成为该帖子/页面的子元素。
您可以在自定义字段中提供一个下拉列表,列出当前帖子/页面上传到上传器的所有上传文件。这是我用来显示文件列表的代码,用户可以选择哪一个是平面图图像:
<select name="chb_homes_for_sale_specifics_floor_plan" style="width:100%;">
<option value="" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], ""); ?>>No Floor Plan</option>
<?php
$args = array(
\'numberposts\' => -1,
\'orderby\' => \'menu_order\',
\'order\' => \'ASC\',
\'post_type\' => \'attachment\',
\'post_parent\' => $post->ID,
\'post_mime_type\' => \'image\'
);
$image = get_posts($args);
if($image) {
foreach($image as $key => $data) : ?>
<option value="<?php echo $data->ID; ?>" <?php selected($custom["chb_homes_for_sale_specifics_floor_plan"][0], $data->ID); ?>><?php echo basename ( get_attached_file( $data->ID ) ); ?></option>
<?php endforeach;
}
?>
</select>