GCBGutenberg
Control Blocks
v1.3.3
Buy

Carousel

Slides your client fills with any blocks, shown one or a few at a time, with arrows, dots and autoplay.

A carousel your client edits slide by slide, on the canvas. Each slide is a block of its own and takes any blocks inside it: a picture, words, or a block of yours. On the page it is a scroll-snap track with arrows and dots, and it swipes on a phone.

A carousel built this way, recorded in the editor: a new slide arrives laid out like the others, ready to type on.

Download example A zip of block folders for your theme. Needs GCB 1.3.1 or later, and nothing else.

What's in the download

  • carousel/ The carousel. Its fields set how many slides show across, the gap, arrows, dots and autoplay.
  • slide/ One slide. Any blocks go inside.

Each folder is an ordinary GCB block: block.json, block.fields.json and render.php, plus a style.css and a view.js where it needs them. There is no build step and no library.

How it's built

The carousel's template marks where the slides go with a <Repeater>. That one marker holds every rule about them: which block a slide is, the label on the Add button, and the fewest and most slides a page may have. WordPress won't save a page outside those limits.

carousel/render.php
<Repeater  allowedBlocks='["gcb/slide"]'  addButtonLabel="Add slide"  min="1"  max="24"  editLayout="carousel"/>

Its fields, from block.fields.json:

FieldType
Slides acrossrange
Gaprange
Arrowstoggle
Dotstoggle
Autoplayrange

view.js is about 4 KB of plain JavaScript with no library behind it. With no script, every slide shows, one after another.

Use it

  1. Unzip the download.
  2. Copy carousel/ and slide/ into your theme's blocks/ folder.
  3. Reload the block editor. The block is in the inserter.

That's all of it. You don't register the block: there's no register_block_type() call and nothing to add to functions.php. GCB registers every folder in your theme's blocks/ folder by itself.

It is your block now. Change the markup, the fields or the script to suit the design. The docs cover every field type and marker used here.

More examples: all examples, or download them together as the GCB Kit.

Build anything in the block editor

Every licence includes all features and a year of updates and support.

Buy GCB from $8.25 a month See pricing