Skip to content

Instantly share code, notes, and snippets.

@dkmy-sec
Created February 7, 2017 18:26
Show Gist options
  • Save dkmy-sec/72007509ff0b2be63b1d46d93e1cd5c3 to your computer and use it in GitHub Desktop.
Save dkmy-sec/72007509ff0b2be63b1d46d93e1cd5c3 to your computer and use it in GitHub Desktop.
<div class="downloads">
<div class="downloads-headers">
<span class="description-title">DESCRIPTION</span>
<span class="download-title">DOWNLOAD LINK</span>
</div>
<div class="download-wrap">
<?php if ( have_rows('file_uploads') ) : ?>
<?php while( have_rows('file_uploads') ) : the_row(); ?>
<?php
//Declare Variable for your ACF Field.
$attachment_id = get_sub_field('file_upload');
//URL variable to extract url from file id return value.
$url = wp_get_attachment_url( $attachment_id );
?>
<div class="download-entry">
<div class="download-description">
<a href="<?php echo $url; ?>" target="_blank"><?php the_sub_field('file_description'); ?></a>
</div>
<div class="download-icon-link">
<div class="download-icon">
<?php if ( get_sub_field('file_icon') ) : $file_icon = get_sub_field('file_icon'); ?>
<img src="<?php echo $file_icon['url']; ?>" alt="<?php echo $file_icon['alt']; ?>"/>
<?php endif; ?>
</div>
<div class="download-link">
<a href="<?php echo $url; ?>" target="_blank"><?php the_sub_field('file_type'); ?> <?php
// Use php filesize to grab the filesize and save as a variable.
$filesize = filesize( get_attached_file( $attachment_id ) );
// Built in WordPress function to convert file size to human readable format size_format($filepath, decimal place).
$filesize = size_format($filesize, 2);
//Echo the Human Readable filesize.
echo $filesize;
?></a>
</div>
</div>
</div>
<?php endwhile; ?>
<?php endif; ?>
</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment