ACF Pro: Upgrade from free, add Documents repeater field with download buttons
This commit is contained in:
+1
-1
File diff suppressed because one or more lines are too long
@@ -197,7 +197,7 @@ function homeproz_register_acf_fields() {
|
||||
'layout' => 'horizontal',
|
||||
),
|
||||
|
||||
// Gallery Tab - Using relationship to media for free ACF
|
||||
// Gallery Tab - ACF Pro Gallery field
|
||||
array(
|
||||
'key' => 'field_property_tab_gallery',
|
||||
'label' => 'Photo Gallery',
|
||||
@@ -209,17 +209,56 @@ function homeproz_register_acf_fields() {
|
||||
'key' => 'field_property_gallery',
|
||||
'label' => 'Property Gallery',
|
||||
'name' => 'property_gallery',
|
||||
'type' => 'relationship',
|
||||
'instructions' => 'Select images from the media library. First image will be the main photo if no featured image is set.',
|
||||
'post_type' => array('attachment'),
|
||||
'post_status' => array('inherit'),
|
||||
'filters' => array('search'),
|
||||
'type' => 'gallery',
|
||||
'instructions' => 'Upload or select property photos. First image will be the main photo if no featured image is set.',
|
||||
'min' => 0,
|
||||
'max' => 30,
|
||||
'return_format' => 'id',
|
||||
'preview_size' => 'medium',
|
||||
'library' => 'all',
|
||||
'mime_types' => 'jpg, jpeg, png, webp',
|
||||
),
|
||||
|
||||
// Documents Tab - ACF Pro Repeater
|
||||
array(
|
||||
'key' => 'field_property_tab_documents',
|
||||
'label' => 'Documents',
|
||||
'name' => '',
|
||||
'type' => 'tab',
|
||||
'placement' => 'top',
|
||||
),
|
||||
array(
|
||||
'key' => 'field_property_documents',
|
||||
'label' => 'Property Documents',
|
||||
'name' => 'property_documents',
|
||||
'type' => 'repeater',
|
||||
'instructions' => 'Upload supporting documents (floor plans, disclosures, surveys, etc.)',
|
||||
'min' => 0,
|
||||
'max' => 10,
|
||||
'layout' => 'table',
|
||||
'button_label' => 'Add Document',
|
||||
'sub_fields' => array(
|
||||
array(
|
||||
'key' => 'field_document_file',
|
||||
'label' => 'File',
|
||||
'name' => 'file',
|
||||
'type' => 'file',
|
||||
'required' => 1,
|
||||
'return_format' => 'array',
|
||||
'library' => 'all',
|
||||
'mime_types' => 'pdf, doc, docx, xls, xlsx',
|
||||
),
|
||||
array(
|
||||
'key' => 'field_document_label',
|
||||
'label' => 'Button Label',
|
||||
'name' => 'label',
|
||||
'type' => 'text',
|
||||
'required' => 1,
|
||||
'instructions' => 'e.g., "Floor Plan", "Property Survey"',
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
// Agent Tab
|
||||
array(
|
||||
'key' => 'field_property_tab_agent',
|
||||
|
||||
@@ -33,6 +33,7 @@ while (have_posts()) :
|
||||
$property_features = get_field('property_features', $property_id);
|
||||
$gallery = get_field('property_gallery', $property_id);
|
||||
$listing_agent = get_field('listing_agent', $property_id);
|
||||
$property_documents = get_field('property_documents', $property_id);
|
||||
|
||||
// Get status from taxonomy
|
||||
$status_terms = get_the_terms($property_id, 'property_status');
|
||||
@@ -140,6 +141,33 @@ while (have_posts()) :
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Documents -->
|
||||
<?php if ($property_documents && is_array($property_documents)) : ?>
|
||||
<section class="property-documents">
|
||||
<ul class="documents-list">
|
||||
<?php foreach ($property_documents as $doc) :
|
||||
if (!$doc['file']) continue;
|
||||
$file = $doc['file'];
|
||||
$label = $doc['label'] ?: $file['filename'];
|
||||
$ext = pathinfo($file['filename'], PATHINFO_EXTENSION);
|
||||
?>
|
||||
<li class="document-item">
|
||||
<a href="<?php echo esc_url($file['url']); ?>" class="document-link btn btn-secondary" target="_blank" download>
|
||||
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" aria-hidden="true">
|
||||
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
|
||||
<polyline points="14 2 14 8 20 8"/>
|
||||
<line x1="12" y1="18" x2="12" y2="12"/>
|
||||
<polyline points="9 15 12 18 15 15"/>
|
||||
</svg>
|
||||
<?php echo esc_html($label); ?>
|
||||
<span class="document-ext">(<?php echo esc_html(strtoupper($ext)); ?>)</span>
|
||||
</a>
|
||||
</li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
</section>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- Description -->
|
||||
<section class="property-description">
|
||||
<h2 class="section-title">Description</h2>
|
||||
|
||||
@@ -161,6 +161,41 @@
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
// Documents
|
||||
.property-documents {
|
||||
margin-bottom: 2rem;
|
||||
}
|
||||
|
||||
.documents-list {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
justify-content: center;
|
||||
gap: 1rem;
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.document-item {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.document-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
|
||||
svg {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.document-ext {
|
||||
font-size: 0.75rem;
|
||||
opacity: 0.7;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
// Description
|
||||
.property-description {
|
||||
margin-bottom: 2rem;
|
||||
|
||||
Reference in New Issue
Block a user