0

I'm creating a custom post type and I have it support featured images but I don't know how to add support for galleries as well as WooCommerce does. The idea is to add another featured image panel which accept multiple images that I can show on the front end.

Thank you for you suggestions on how manage both adding support in back end and echo it in the front end.

1

You can use gallery-metabox. Its open source and easy to use;

https://github.com/zulfnore/gallery-metabox

From Readme ;

Include the gallery.php in your functions.php:

require_once 'gallery-metabox/gallery.php';

Specify where you want the gallery metabox to show on line 17 in gallery.php. You can pass an array to have it show up on multiple post types, custom post types are also allowed:

$types = array('post', 'page', 'custom-post-type');

In your template inside a loop, grab the IDs of all the images with the following:

$images = get_post_meta($post->ID, 'vdw_gallery_id', true);

Then you can loop through the IDs and call wp_get_attachment_link or wp_get_attachment_image to display the images with or without a link respectively:

foreach ($images as $image) { echo wp_get_attachment_link($image, 'large'); // echo wp_get_attachment_image($image, 'large'); }

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.