Block Preview not working
-
Hey there
I’m trying to use your plugin to create a custom block that is fetching a lot of images in a certain upload folder and create a gallery out of it. Within the block-editor view in the backend, it’s working as expected. But if I’m trying to preview the block in the frontend, nothing happens. The whole block is not being outputted. Any ideas?
Here’s the code i’m using:
<?php // custom block to create a gallery based on image folder in uploads $home_url = home_url() . '/website/wp-content/uploads' . block_field('imagefolder'); $upload_dir = wp_upload_dir(); $image_folder = $upload_dir['basedir'] . block_field('imagefolder'); $files = glob($image_folder . "/*.jpg"); foreach($files as $image_name) { echo ($files ? '<div class="singlepost__media__image has-pswp"> <figure itemprop="associatedMedia" itemscope itemtype="https://schema.org/ImageObject"> <a href="'.$home_url.basename($image_name).'" itemprop="contentUrl" class="singlepost__media__image__link"> <img class="lazy" data-object-fit="cover" alt="'.$home_url.basename($image_name).'" src="'.$home_url.basename($image_name).'"> </a> </figure> </div>' : ''); } ?>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Block Preview not working’ is closed to new replies.