link-block.php
2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?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');
$new_window="";
if($fields['new_window']){
$new_window ='target="_blank"';
}
$return = '';
if($fields['modal']){
$new_window = 'href="javascript:void(0)" data-bs-toggle="modal" data-bs-target="#Modal"';
$page_data = get_page_by_path( $fields['link'] );
$return .= '<div class="modal fade" id="Modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-lg" role="document">
<div class="modal-content">
<div class="modal-body">
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
<div class="body-content">';
$return .= $page_data->post_content;
$return .='</div></div></div></div></div>';
echo $return;
}
switch($style){
case 'image': ?>
<a class="block-link" <?php echo $new_window; ?> href="<?php echo $fields['link']; ?>">
<div class="link-block single">
<div class="link-block image" style="background-image: url('<?php the_field('image'); ?>')">
</div>
<div class="link"><?php echo $fields['link_text']; ?> </div>
</div>
</a>
<?php
break;
case 'text': ?>
<a class="block-link" <?php echo $new_window; ?> 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" <?php echo $new_window; ?> 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-content"><div class="img" style="background-image: url('<?php the_field('image'); ?>')"> </div></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
};