Home › Forums › Add-ons › Gallery Field › Use files in Gallery field
Hi everyone,
I wanted to know if there were indications against using files (zip, ppt, pdf, doc, …) in the gallery field?
Knowing that I will only use the name and the url of the file.
Indeed, the file field (combined with a repeater field) allows to select one file at a time and “weighed down” the interface. (30 files = 30 lines, for example)
Well, it would cause problems because it will try to return an array of images. On the other hand, if you used the code at the bottom of the gallery doc page http://www.advancedcustomfields.com/resources/gallery/ “Create a WP gallery” this returns an array of attachment ID values and you could use those with wp_get_attachment_url()
. However, I’ve never tried to add files to a gallery field, have you? Will it allow files that are not images?
Hi John,
Here is my application:
<?php $files = get_field('files');
foreach( $files as $file ): ?>
<li>
<a href="<?php echo $file['url']; ?>">
<?php echo $file['title']; ?>
</a>
</li>
<?php endforeach; ?>
It works (see attachments), but I don’t know if it will eventually produce errors afterwards.
It is most likely causing warnings in the background. I’m pretty sure that when the gallery is retrieved it uses the php function getimagesize() and using this function on non image files usually causes warnings. They generally won’t be a problem unless you turn on error display.
So if I do not have a displayed error, I can use this solution? 🙂
I don’t see why not, I would probably return it as an array of ID values and get the attachment urls myself, but that’s because I don’t like warnings.
The topic ‘Use files in Gallery field’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.