Home Forums Add-ons Gallery Field Use files in 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 “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 ): ?>
    		<a href="<?php echo $file['url']; ?>">
    			 <?php echo $file['title']; ?>
    <?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.

Viewing 6 posts - 1 through 6 (of 6 total)

The topic ‘Use files in Gallery field’ is closed to new replies.