Within the course of of making a complete gallery show in WordPress powered by Customized Put up Sorts, we’ve shared the code for how one can get all submit attachments in WordPress apart from Featured Picture. We’ve got additionally confirmed you how one can add further fields to the WordPress Media uploader. On this article, we’ll present you how one can use the extra fields within the media uploader and show them in a customized single attachments template.
Earlier than we begin, it will be significant that you simply perceive how the template hierarchy works for attachments. You possibly can both specify it like mime_type.php. Mime kind examples (picture.php, video.php, software.php and so on). For specifying it only for a sure picture kind, you’ll be able to say image_gif.php. If the mime_type.php just isn’t discovered, then it seems for attachment.php, then single-attachment.php, then single.php, then index.php.
It depends upon how customized of a challenge you might be working for, you might not must create image_gif.php. You possibly can merely suffice for picture.php and even attachment.php.
All you must do is open a clean file and duplicate all your single.php content material in there. It can save you it as single-attachment.php or another mime_type that you really want. Then exchange the loop code with one thing like this:
The code above merely shows the Picture Title. Beneath it, it’ll show Writer’s title and URL which we added as further fields in our earlier article. Then it seems for the picture and shows the total measurement. You possibly can customise it to indicate another measurement you probably have further picture sizes.
Remaining Final result:
Now that we’ve lined all three foremost points of this gallery that we have been going to create, within the subsequent article, we’ll present you the way it seems when all issues are pieced collectively. This fashion, you need to use WordPress’s built-in mechanism to create a full-featured gallery with albums. No further plugins required.