link-block.php 1.98 KB
<?php

/**
 * Link Block Template.
 *
 * @param   array $block The block settings and attributes.
 * @param   string $content The block inner HTML (empty).
 * @param   bool $is_preview True during AJAX preview.
 * @param   (int|string) $post_id The post ID this block is saved to.
 */



$fields = get_fields();
$style = get_field('style');

switch($style){  
    case 'image': ?>
        <a class="block-link" href="<?php echo $fields['link']; ?>">
            <div class="link-block image" style="background-image: url('<?php the_field('image'); ?>')">
                 <div class="link"><?php echo $fields['link_text']; ?> </div>   
            </div> 
        </a>   
    <?php
    break;
    case 'text': ?>
        <a class="block-link" href="<?php echo $fields['link']; ?>">
            <div class="link-block Text">
                <?php echo $fields['text']; ?>  
                <div class="link"><?php echo $fields['link_text']; ?> </div>   
            </div>
        </a>     
    <?php
    break;
    case 'image-text':
    if($fields['link'] != ""){?>
        <a class="block-link" href="<?php echo $fields['link']; ?>">
            <div class="link-block image-text">
            <div class="row">
                <div class="col-md-12 col-lg-6 text"><?php echo $fields['text']; ?></div>
                <div class="col-md-12 col-lg-6 img" style="background-image: url('<?php the_field('image'); ?>')"> </div>
            </div>    
                <div class="link"><?php echo $fields['link_text']; ?> </div>   
            </div>
        </a>           
    <?php
    }else{ ?>
        <div class="link-block image-text no-link">
            <div class="row">
                <div class="col-md-12 col-lg-6 text"><?php echo $fields['text']; ?></div>
                <div class="col-md-12 col-lg-6 img" style="background-image: url('<?php the_field('image'); ?>')"> </div>
            </div>    
        </div>  
   <?php }
    break;  
    default: ?>    
    <p>Please select style.</p>  
    
    <?php };