diff --git a/src/blocks/carousel/create-swiper.js b/src/blocks/carousel/create-swiper.js index b18400e15..1e7262df1 100644 --- a/src/blocks/carousel/create-swiper.js +++ b/src/blocks/carousel/create-swiper.js @@ -135,6 +135,9 @@ export default function createSwiper( els, config = {} ) { }, slideChange() { + if ( this.slides.length < 1 ) { + return; // No slides, no need to do anything. + } const currentSlide = this.slides[ this.activeIndex ]; deactivateSlide( this.slides[ this.previousIndex ] ); diff --git a/src/blocks/carousel/edit.js b/src/blocks/carousel/edit.js index 39a891a31..40660d7fc 100644 --- a/src/blocks/carousel/edit.js +++ b/src/blocks/carousel/edit.js @@ -113,7 +113,7 @@ class Edit extends Component { initializeSwiper( initialSlide ) { const { latestPosts } = this.props; - if ( latestPosts && latestPosts.length ) { + if ( latestPosts ) { const { aspectRatio, autoplay, delay, slidesPerView } = this.props.attributes; const swiperInstance = createSwiper( { diff --git a/src/blocks/carousel/view.php b/src/blocks/carousel/view.php index 667f952a4..372e65fb2 100644 --- a/src/blocks/carousel/view.php +++ b/src/blocks/carousel/view.php @@ -34,7 +34,7 @@ function newspack_blocks_render_block_carousel( $attributes ) { $article_query = new WP_Query( Newspack_Blocks::build_articles_query( $attributes, apply_filters( 'newspack_blocks_block_name', 'newspack-blocks/carousel' ) ) ); if ( false === $article_query->have_posts() ) { - return; + return ''; } $counter = 0;