acf_field_gallery::render_field() public ACF 3.6
Create the HTML interface for your field
{} Это метод класса: acf_field_gallery{}
Хуков нет.
Возвращает
Null. Ничего.
Использование
$acf_field_gallery = new acf_field_gallery(); $acf_field_gallery->render_field( $field );
- $field (обязательный)
- -
Список изменений
С версии 3.6 | Введена. |
Код acf_field_gallery::render_field() acf field gallery::render field ACF 5.9.1
<?php
function render_field( $field ) {
// Enqueue uploader assets.
acf_enqueue_uploader();
// Control attributes.
$attrs = array(
'id' => $field['id'],
'class' => "acf-gallery {$field['class']}",
'data-library' => $field['library'],
'data-preview_size' => $field['preview_size'],
'data-min' => $field['min'],
'data-max' => $field['max'],
'data-mime_types' => $field['mime_types'],
'data-insert' => $field['insert'],
'data-columns' => 4
);
// Set gallery height with deafult of 400px and minimum of 200px.
$height = acf_get_user_setting('gallery_height', 400);
$height = max( $height, 200 );
$attrs['style'] = "height:{$height}px";
// Load attachments.
$attachments = array();
if( $field['value'] ) {
// Clean value into an array of IDs.
$attachment_ids = array_map('intval', acf_array($field['value']));
// Find posts in database (ensures all results are real).
$posts = acf_get_posts(array(
'post_type' => 'attachment',
'post__in' => $attachment_ids,
'update_post_meta_cache' => true,
'update_post_term_cache' => false
));
// Load attatchment data for each post.
$attachments = array_map('acf_get_attachment', $posts);
}
?>
<div <?php acf_esc_attr_e($attrs); ?>>
<input type="hidden" name="<?php echo esc_attr($field['name']); ?>" value="" />
<div class="acf-gallery-main">
<div class="acf-gallery-attachments">
<?php if( $attachments ): ?>
<?php foreach( $attachments as $i => $attachment ):
// Vars
$a_id = $attachment['ID'];
$a_title = $attachment['title'];
$a_type = $attachment['type'];
$a_filename = $attachment['filename'];
$a_class = "acf-gallery-attachment -{$a_type}";
// Get thumbnail.
$a_thumbnail = acf_get_post_thumbnail($a_id, $field['preview_size']);
$a_class .= ($a_thumbnail['type'] === 'icon') ? ' -icon' : '';
?>
<div class="<?php echo esc_attr($a_class); ?>" data-id="<?php echo esc_attr($a_id); ?>">
<input type="hidden" name="<?php echo esc_attr($field['name']); ?>[]" value="<?php echo esc_attr($a_id); ?>" />
<div class="margin">
<div class="thumbnail">
<img src="<?php echo esc_url($a_thumbnail['url']); ?>" alt="" />
</div>
<?php if( $a_type !== 'image' ): ?>
<div class="filename"><?php echo acf_get_truncated( $a_filename, 30 ); ?></div>
<?php endif; ?>
</div>
<div class="actions">
<a class="acf-icon -cancel dark acf-gallery-remove" href="#" data-id="<?php echo esc_attr($a_id); ?>" title="<?php _e('Remove', 'acf'); ?>"></a>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
<div class="acf-gallery-toolbar">
<ul class="acf-hl">
<li>
<a href="#" class="acf-button button button-primary acf-gallery-add"><?php _e('Add to gallery', 'acf'); ?></a>
</li>
<li class="acf-fr">
<select class="acf-gallery-sort">
<option value=""><?php _e('Bulk actions', 'acf'); ?></option>
<option value="date"><?php _e('Sort by date uploaded', 'acf'); ?></option>
<option value="modified"><?php _e('Sort by date modified', 'acf'); ?></option>
<option value="title"><?php _e('Sort by title', 'acf'); ?></option>
<option value="reverse"><?php _e('Reverse current order', 'acf'); ?></option>
</select>
</li>
</ul>
</div>
</div>
<div class="acf-gallery-side">
<div class="acf-gallery-side-inner">
<div class="acf-gallery-side-data"></div>
<div class="acf-gallery-toolbar">
<ul class="acf-hl">
<li>
<a href="#" class="acf-button button acf-gallery-close"><?php _e('Close', 'acf'); ?></a>
</li>
<li class="acf-fr">
<a class="acf-button button button-primary acf-gallery-update" href="#"><?php _e('Update', 'acf'); ?></a>
</li>
</ul>
</div>
</div>
</div>
</div>
<?php
}