Custom ACF blocks

Panel Block

This block called ‘Panel’ pulls in content from the posts saved in the Panel CPT. Content saved in this area of site is meant to be reusable on different areas of the site, an example is a ‘subscribe to news’ panel.

<?php
/**
 * Block Name: Panel
 *
 * This is the template that displays the Panel
 */
$id = 'wp-panel-' . $block['id'];
$align_class = $block['align'] ? 'align' . $block['align'] : '';
$posts = get_field('add_panel');
if( $posts ): ?>
    <div id="<?php echo $id; ?>" class="wp-block wp-block-panel <?php echo $align_class; ?>">
	    <?php foreach( $posts as $post): ?>
	        <?php setup_postdata($post); ?>
	        <?php the_content();  ?>
	    <?php endforeach; ?>
    </div>
    <?php wp_reset_postdata(); ?>
<?php endif; ?>

Example panel

The above panel is inserted like this:

We prefer this method to the use of reusable blocks because panels are easier to get to, and improve. Importantly they can also contain numerous blocks. So, for example, you can have several blocks inside a section or column block.

The example newsletter panel above contains a heading and form block inside a section block that is full width with a grey background colour.

Below is a reusable block , it works similar

Entry content block

We can also bring in content for another CPT using the Entry Content block. This works exactly like the panel block but you can pick from any other content area in the site, and the post is inserted in a entry-content div, Example case study here:

NEW ACF blocks (2024)

Search the site


Address

123 Main Street
Town
City
P05T C0D3

Tel: 01234 567 899

Mob: 01234 567 899

Email: ben@gomopress.com


Copyright 2023. Blah blah blah Company Limited