skip to Main Content

I created a custom post type called ‘products’ and want to upload multiple images to a single product, similar to how it’s done in WooCommerce, but I’m unable to do so.

i tried the plugins but they are not working for me. i am using ocean wp free theme

2

Answers


  1. You can use the ACF plugin to achieve the desired functionality. ACF includes a "Gallery" field, allowing you to upload multiple images. You can then retrieve the gallery field as needed.

    For example:

    $gallery = get_field('my_gallery');
    if( $gallery ): ?>
        <div class="gallery">
            <?php foreach( $gallery as $image ): ?>
                <div class="gallery-item">
                    <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                    <p><?php echo esc_html($image['caption']); ?></p>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
    

    I hope this helps!

    Login or Signup to reply.
  2. Use the ACF (Advanced Custom Fields) plugin. It provides a "Gallery" field for uploading multiple images. Here’s how to display them:

    <?php
        $gallery = get_field('my_gallery');
    if ($gallery): ?>
        <div class="gallery">
            <?php foreach ($gallery as $image): ?>
                <div class="gallery-item">
                    <img src="<?php echo esc_url($image['url']); ?>" alt="<?php echo esc_attr($image['alt']); ?>" />
                    <p><?php echo esc_html($image['caption']); ?></p>
                </div>
            <?php endforeach; ?>
        </div>
    <?php endif; ?>
    

    This code retrieves and displays the gallery images.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search