Skip to content

Instantly share code, notes, and snippets.

@billerickson
Created February 4, 2022 14:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save billerickson/77125954c323de6999eb19322f42ebe0 to your computer and use it in GitHub Desktop.
Save billerickson/77125954c323de6999eb19322f42ebe0 to your computer and use it in GitHub Desktop.
<?php
/**
* Register Blocks
*/
function be_register_blocks() {
acf_register_block_type(
[
'title' => __( 'Partners', 'cwp2021' ),
'name' => 'partners',
'render_template' => 'partials/blocks/partners.php',
'category' => 'cultivatewp',
'icon' => cwp_icon( [ 'icon' => 'cultivatewp', 'group' => 'color', 'force' => true ] ),
'mode' => 'auto',
'supports' => [
'align' => false,
'anchor' => true,
'customClassName' => true,
],
]
);
}
add_action( 'acf/init', 'be_register_blocks' );
<?php
/**
* Partners Listing block
*
* @package CultivateWP2022
* @author CultivateWP
* @since 1.0.0
* @license GPL-2.0+
**/
$classes = [ 'block-partners' ];
if ( ! empty( $block['className'] ) ) {
$classes = array_merge( $classes, explode( ' ', $block['className'] ) );
}
if ( ! empty( $block['align'] ) ) {
$classes[] = 'align' . $block['align'];
}
printf(
'<div class="%s"%s>',
esc_attr( join( ' ', $classes ) ),
! empty( $block['anchor'] ) ? ' id="' . esc_attr( sanitize_title( $block['anchor'] ) ) . '"' : '',
);
$partners = get_field( 'partners' );
foreach( $partners as $partner ) {
echo '<div class="partner">';
echo '<a href="' . esc_url( $partner['url'] ) . '" aria-hidden="true" target="blank" rel="noopener noreferer">' . wp_get_attachment_image( $partner['image'], 'thumbnail' ) . '</a>';
echo '<div>';
echo '<p><a href="' . esc_url( $partner['url'] ) . '">' . esc_html( $partner['name'] ) . '</a></p>';
if ( ! empty( $partner['title'] ) ) {
echo '<p>' . esc_html( $partner['title'] ) . '</p>';
}
echo '</div>';
echo '</div>';
}
echo '</div>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment