Can blocks be used as a conditional statement on a theme?

Question

I’m new at using the block editor and need help. I have ACF Pro and need help. I create a block that has radio buttons called article_type that has four options: post, gallery, image, audio and video.

Can blocks be used as conditional statement on a theme?

So, for example, can I use that block to show or hide additional items based on what’s selected? I tried to do <?php if( get_field('article_type') == 'post' ) { } <?php endif;?> on my index.php and it doesn’t work.

This is what I have in my functions.php file:

function register_acf_block_types() {
// register a testimonial block.
acf_register_block_type(array(
    'name'              => 'settings',
    'title'             => __('OPBY settings'),
    'description'       => __('Settings for a post'),
    'category'          => 'formatting',
    'mode'              => 'edit',
    'icon'              => 'admin-comments',
    'keywords'          => array( 'opby', 'openbayou', 'settings' ),
));
}
// Check if function exists and hook into setup.
if( function_exists('acf_register_block_type') ) {
    add_action('acf/init', 'register_acf_block_types');
};
function be_post_block_template() {
   $post_type_object = get_post_type_object( 'post' );
   $post_type_object->template = array(
      array( 'core/paragraph' ),
      array( 'acf/settings' ),
   );
}
add_action( 'init', 'be_post_block_template' );
0
, Gregory Schultz 8 months 0 Answers 82 views 0

Leave an answer