Skip to content

Instantly share code, notes, and snippets.

@coreymcollins
Last active March 23, 2021 03:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save coreymcollins/65b72f97c9a491e89badf9386dbb4f7c to your computer and use it in GitHub Desktop.
Save coreymcollins/65b72f97c9a491e89badf9386dbb4f7c to your computer and use it in GitHub Desktop.
ACF Filters Post
<?php
/**
* The template used for displaying a CTA block.
*
* @package _s
*/
// Set up fields.
$title = get_sub_field( 'title' );
$text = get_sub_field( 'text' );
$button_url = get_sub_field( 'button_url' );
$button_text = get_sub_field( 'button_text' );
$animation_class = _s_get_animation_class();
// Store our block args so we can filter them later.
$default_args = array(
'title' => $title,
'button_url' => $button_url,
'button_text' => $button_text,
'animation_class' => $animation_class,
'container_class' => '',
);
// Filter our args.
$block_args = array_merge( $default_args, apply_filters( '_s_cta_block_args', $default_args ) );
// Start a <container> with possible block options.
_s_display_block_options(
array(
'container' => 'section', // Any HTML5 container: section, div, etc...
'class' => 'content-block grid-container call-to-action' . esc_attr( $block_args['container_class'] ), // Container class.
)
);
?>
<div class="grid-x<?php echo esc_attr( $block_args['animation_class'] ); ?>">
<div class="cell">
<?php if ( $block_args['title'] ) : ?>
<h3 class="cta-title"><?php echo esc_html( $block_args['title'] ); ?></h3>
<?php endif; ?>
<?php if ( $block_args['text'] ) : ?>
<h4 class="cta-text"><?php echo esc_html( $block_args['text'] ); ?></h4>
<?php endif; ?>
</div>
<div class="cell">
<?php if ( $block_args['button_url'] && $block_args['button_text'] ) : ?>
<a class="button cta-button" href="<?php echo esc_url( $block_args['button_url'] ); ?>"><?php echo esc_html( $block_args['button_text'] ); ?></a>
<?php endif; ?>
</div>
</div><!-- .grid-x -->
</section><!-- .cta-block -->
<?php
/**
* The template used for displaying a CTA block.
*
* @package _s
*/
// Set up fields.
$title = get_sub_field( 'title' );
$text = get_sub_field( 'text' );
$button_url = get_sub_field( 'button_url' );
$button_text = get_sub_field( 'button_text' );
$animation_class = _s_get_animation_class();
// Start a <container> with possible block options.
_s_display_block_options(
array(
'container' => 'section', // Any HTML5 container: section, div, etc...
'class' => 'content-block grid-container call-to-action', // Container class.
)
);
?>
<div class="grid-x<?php echo esc_attr( $animation_class ); ?>">
<div class="cell">
<?php if ( $title ) : ?>
<h3 class="cta-title"><?php echo esc_html( $title ); ?></h3>
<?php endif; ?>
<?php if ( $text ) : ?>
<h4 class="cta-text"><?php echo esc_html( $text ); ?></h4>
<?php endif; ?>
</div>
<div class="cell">
<?php if ( $button_url && $button_text ) : ?>
<a class="button cta-button" href="<?php echo esc_url( $button_url ); ?>"><?php echo esc_html( $button_text ); ?></a>
<?php endif; ?>
</div>
</div><!-- .grid-x -->
</section><!-- .cta-block -->
/**
* Filters the args in the CTA block on the Customers Archive.
*
* @param array $block_args The default args of our block.
* @return array The updated arguments for our block.
* @author Corey Collins
*/
function _s_filter_customer_archive_cta( $block_args = array() ) {
// Bail if we're not on our specific category.
if ( ! has_category( 'great-category' ) ) {
return $block_args;
}
// Set our values.
return array(
'title' => __( 'Great Category? More like Best Category!', '_s' ),
'button_text' => __( 'Learn More About This Very Special Category', '_s' ),
'button_url' => 'https://webdevstudios.com/an-alternate-url',
'container_class' => ' cta-great-category',
);
}
add_filter( '_s_cta_block_args', '_s_filter_customer_archive_cta' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment