0

I am using the ACF Photo Gallery plugin (ACF addon that adds an image gallery option). I'm trying to add the option of giving my own CSS class to a particular image, all by the tutorial ->https://wordpress.org/plugins/navz-photo-gallery/ (Usage, Add Extra Field), but unfortunately for some reason the CSS class does not appear In the code. I paste below my comment code (there is not much). Where did I make a mistake?

/// I put this to functions.php, in edition in particular image window appears with css class field <?php function my_extra_gallery_fields( $args, $attachment_id, $field ){ $args['class'] = array('type' => 'text', 'label' => 'Kolor produktu', 'name' => 'class', 'value' => get_field($field . '_class', $attachment_id) ); /// I think the problem may be here return $args; } add_filter( 'acf_photo_gallery_image_fields', 'my_extra_gallery_fields', 10, 3 ); ?> /// I put this code to single-portfolio.php <?php $images = acf_photo_gallery('gallery_images', $post->ID); /// gallery_images to slug pola galeria w ACF if( count($images) ): foreach($images as $image): $full_image_url= $image['full_image_url']; $class = get_field('gallery_images_class', $id); endforeach; endif; ?> /// This code displays image, CSS class should appers, but it doesn't <?php foreach($images as $image) { ?> <img src="<?php echo $image['full_image_url']; ?>" class="<?php echo $class; ?>" > <?php } ?> 

    1 Answer 1

    1

    Try this code at the place where you want your gallery:

    <?php $images = acf_photo_gallery('gallery_images', $post->ID); /// gallery_images to slug pola galeria w ACF if( count($images) ): foreach($images as $image): $full_image_url= $image['full_image_url']; $class = get_field('gallery_images_class', $id); echo '<img src="'.$image['full_image_url'].'" class="'.$class.'" >'; endforeach; endif; ?> 

    Do try to check if '$id' gives you the image/post id (not sure what is needed here).

    EDIT: Please check if $id and $class are correct. you can do this by using this code:

    <?php $images = acf_photo_gallery('gallery_images', $post->ID); /// gallery_images to slug pola galeria w ACF if( count($images) ): foreach($images as $image): $full_image_url= $image['full_image_url']; $class = get_field('gallery_images_class', $image['id']); echo '<img src="'.$image['full_image_url'].'" class="'.$class.'" >'; endforeach; endif; ?> 

    It could be possible that `$image' in your foreach has an ID. Try to use that one instead.

    9
    • Thanks for reply. Unfortunately, it is the same as before. I tried 'echo $id' and I received post ID. I think I need images ID? What you suggest?
      – Marek
      CommentedMay 17, 2017 at 9:24
    • @Marek check my edit!
      – xvilo
      CommentedMay 17, 2017 at 9:29
    • OK, I pasted your new code and I received blank page, but in source code in the place where the slider should be I see "int(2278) bool(false)". 2278 - this is the post ID.
      – Marek
      CommentedMay 17, 2017 at 9:35
    • @Marek can you change ` die(var_dump($id, $class));` to ` die(var_dump($image));` ? And then post it on pastebin and give us the link?
      – xvilo
      CommentedMay 17, 2017 at 9:36
    • OK, link to pastebin after change to var_dump($image) -> pastebin.com/Yrw7KCb6
      – Marek
      CommentedMay 17, 2017 at 9:40

    Start asking to get answers

    Find the answer to your question by asking.

    Ask question

    Explore related questions

    See similar questions with these tags.