0

I got the code below to work for a container with the html in a Wordpress page template. How does this work for Block (a Gutenberg block)?

For templates it worked with the following in functions.php. (Got it here:https://www.stackoverflow.com/questions/66552723/how-show-media-gallery-carbon-fields-wordpress/67766361#67766361)

    Container::make( 'post_meta', __( 'Gallery', 'single' ) )
    ->where( 'post_type', '=', 'page' )
    ->add_fields( array(
        Field::make( 'media_gallery', 'crb_media_gallery', 'add images for a gallery' )
        ->set_type(  'image'  )

With this in a page template:

<div class="masonry-wall">
    <?php $gallery  = carbon_get_post_meta( get_the_ID(), 'crb_media_gallery' );
        foreach( $gallery  as $i => $image ){
        echo '<div class="masonry-brick">';
        echo '<img src="'.wp_get_attachment_url( $image ).'" class="">';
        echo '</div>';
        }
    ?>
</div>

But this didn't work for a block:

Block::make( __( 'Gallery' ) )
                ->add_fields( array(
                    Field::make( 'media_gallery', 'carbon_media_gallery', 'Galerie' )
                    ->set_type(  'image'  ),
                ) )
                ->set_render_callback( function ( $fields, $attributes, $inner_blocks ) {
                    ?>
    <div class="masonry-brick">
        <?php $gallery  = carbon_get_post_meta( get_the_ID(), 'carbon_media_gallery' );
           foreach( $gallery  as $i => $image ){
           echo '<img src="'.wp_get_attachment_url( $image ).'>';
           }
        ?>
    </div>  
<?php
} );
t'blanco
  • 1
  • 3

0 Answers0