Cycle2 Slideshow Fails to Initialize in WP Block Preview
-
Hello, I have created a new block using the register_acf_block_types function as demonstrated here.
// Register ACF blocks function register_acf_block_types() { acf_register_block_type(array( 'name' => 'Slideshow', 'title' => __('Slideshow'), 'description' => __('A slideshow.'), 'render_template' => 'includes/slideshow.php', 'category' => 'layout', 'icon' => 'slides', 'keywords' => array( 'slideshow', 'gallery', 'images' ), 'post_types' => array('news', 'page'), )); } // Check if function exists and hook into setup. if( function_exists('acf_register_block_type') ) { add_action('acf/init', 'register_acf_block_types'); }
The images display properly in both the block edit and preview modes. What I’m struggling to accomplish is to make the Cycle2 slideshow initialize in the block preview mode. I’m using the correct “cycle-slideshow” class which should auto initialize.
The Cycle2 script is successfully enqueued in the page editor via:
function my_block_plugin_editor_scripts() { wp_enqueue_script( 'my-block-editor-js', get_theme_file_uri('/scripts/jquery.cycle2.min.js'), [ 'wp-blocks', 'wp-element', 'wp-components', 'wp-i18n' ] ); wp_enqueue_script( 'cycle2swipe', get_template_directory_uri() . '/scripts/jquery.cycle2.swipe.min.js', array(), '1.0.0', true, ['wp-blocks'] ); } // Hook the enqueue functions into the editor add_action( 'enqueue_block_editor_assets', 'my_block_plugin_editor_scripts' );
<?php $images = get_field('slideshow'); ?> <div class="slideshow cycle-slideshow" data-cycle-fx="fadeout" data-cycle-manual-fx="fadeout" data-cycle-speed=2000 data-cycle-timeout=6000 data-cycle-prev="#prev" data-cycle-next="#next" data-cycle-swipe=true data-cycle-swipe-fx="fadeout" data-cycle-manual-speed="300" data-cycle-slides=".slide" data-cycle-pause-on-hover="true" data-cycle-random="false" > <?php foreach( $images as $image ): ?> <div class="slide"> <img src="<?php echo $image['sizes']['banner']; ?>" alt="<?php echo $image['alt']; ?>" /> </div><!--slide--> <?php endforeach; ?> </div><!--slideshow-->
This is my first attempt to work with the block preview so I’m a bit unsure as to what I’m missing. Assuming it’s something obvious! Any help is appreciated!
Viewing 8 replies - 1 through 8 (of 8 total)
Viewing 8 replies - 1 through 8 (of 8 total)
- The topic ‘Cycle2 Slideshow Fails to Initialize in WP Block Preview’ is closed to new replies.