Basic Functions
$downloads = get_field( "product_downloads" );
$type = get_sub_field('download_type');
Repeater Fields
<?php //<-- Do not copy
$downloads = get_field( "product_downloads" );
if( have_rows('product_downloads') ):
while ( have_rows('product_downloads') ) : the_row();
$type = get_sub_field('download_type');
$title = get_sub_field('download_title');
$file = get_sub_field('download_file');
$fileURL = wp_get_attachment_url($file);
$pdfIcon = plugins_url('/img/pdf-logo.png', __FILE__);
$AiIcon = plugins_url('/img/adobe-illustrator-logo.png', __FILE__);
$IdIcon = plugins_url('/img/indesign-logo.png', __FILE__);
if ($type === 'pdf') { ?>
<div class="download-item">
<img src="<?php echo $pdfIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
} elseif ($type === 'adobe-illustrator') { ?>
<div class="download-item">
<img src="<?php echo $AiIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
} elseif ($type === 'adobe-indesign') { ?>
<div class="download-item">
<img src="<?php echo $IdIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
}
endwhile;
else :
echo 'No Templates Available';
endif;
Add the code above into a shortcode to use in posts/products.
<?php //<-- Do not copy
function product_downloads_repeater_shortcode(){
$downloads = get_field( "product_downloads" );
if( have_rows('product_downloads') ):
while ( have_rows('product_downloads') ) : the_row();
$type = get_sub_field('download_type');
$title = get_sub_field('download_title');
$file = get_sub_field('download_file');
$fileURL = wp_get_attachment_url($file);
$pdfIcon = plugins_url('/img/pdf-logo.png', __FILE__);
$AiIcon = plugins_url('/img/adobe-illustrator-logo.png', __FILE__);
$IdIcon = plugins_url('/img/indesign-logo.png', __FILE__);
if ($type === 'pdf') { ?>
<div class="download-item">
<img src="<?php echo $pdfIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
} elseif ($type === 'adobe-illustrator') { ?>
<div class="download-item">
<img src="<?php echo $AiIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
} elseif ($type === 'adobe-indesign') { ?>
<div class="download-item">
<img src="<?php echo $IdIcon ?>" width="35" class="downloadsLogo"><a href="<?php echo $fileURL ?>" download>Download <?php echo $title?></a>
</div><?php
}
endwhile;
else :
echo 'No Templates Available';
endif;
}
add_shortcode('productDownloadsRepeater', 'product_downloads_repeater_shortcode');
//ACCESS FUNCTION BY USING THE SHORTCODE --> [productDownloadsRepeater]