-
Notifications
You must be signed in to change notification settings - Fork 1
/
shortcode.php
155 lines (119 loc) · 4.37 KB
/
shortcode.php
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
<?php
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
class baMaryGoRoundSC {
function __construct() {
add_shortcode('mary_go_round', array($this,'mgr_sc'));
}
function mgr_sc($atts, $content = null){
// globals
global $post;
$hash = rand();
// sc defaults
$defaults = array(
'id' => '',
'brand' => '',
'color' => '',
'items' => 4,
'slidespeed' => 200,
'margin' => '',
'imgsize' => 'medium',
'captions' => 'false',
'linksnewwindow' => '',
'lightbox' => '',
'autoplay' => 'false',
'autoheight' => 'false',
'navigation' => 'false',
'pagination' => 'true',
'paginationnumbers' => 'false',
'singleitem' => 'false',
'itemsdesktop' => '1199,3',
'itemsdesktopsmall' => '979,3',
'itemstablet' => '768,2',
'itemsmobile' => '479,1'
);
$atts = shortcode_atts($defaults, $atts);
// Enqueue styles and scripts
wp_enqueue_script('mgr-script');
wp_enqueue_style('mgr-style');
// LB scripts on demand
if($atts['lightbox']){
wp_enqueue_script('mgr-lb-script');
wp_enqueue_style('mgr-lb-style');
}
?>
<!-- Mary Go Round Instantiation- by @nphaskins -->
<script>
jQuery(document).ready(function(){
jQuery('#mgr-carousel-<?php echo $hash;?>').owlCarousel({
baseClass: 'mgr-carousel',
items: <?php echo $atts['items'];?>,
singleItem: <?php echo $atts['singleitem'];?>,
slideSpeed: <?php echo $atts['slidespeed'];?>,
autoPlay: <?php echo $atts['autoplay'];?>,
autoHeight: <?php echo $atts['autoheight'];?>,
navigation: <?php echo $atts['navigation'];?>,
pagination: <?php echo $atts['pagination'];?>,
paginationNumbers: <?php echo $atts['paginationnumbers'];?>,
<?php if(!$atts['singleitem']) { ?>
itemsDesktop: [<?php echo $atts['itemsdesktop'];?>],
itemsDesktopSmall: [<?php echo $atts['itemsdesktopsmall'];?>],
itemsTablet: [<?php echo $atts['itemstablet'];?>],
itemsMobile: [<?php echo $atts['itemsmobile'];?>]
<?php } ?>
});
<?php if($atts['lightbox']) { ?>
jQuery('.mgr-group-<?php echo $hash;?>').colorbox({
rel:'mgr-group',
onClickNext: false,
});
<?php } ?>
});
</script>
<!-- Margy Go Round Branding- by @nphaskins -->
<?php if ( $atts['brand'] || $atts['color'] || $atts['margin'] ) { ?>
<style>
#mgr-carousel-<?php echo $hash;?> .owl-controls .owl-buttons div{
background: <?php echo $atts['brand'];?>;
color:<?php echo $atts['color'];?>;
}
#mgr-carousel-<?php echo $hash;?> .owl-controls .owl-page span{
background: <?php echo $atts['brand'];?>;
}
<?php if($atts['margin']) {?>
#mgr-carousel-<?php echo $hash;?> .owl-item .item{
margin: 0 <?php echo $atts['margin'];?>;
}
<?php } ?>
</style>
<?php }
do_action('mgr_before');
$out = sprintf('<div id="mgr-carousel-%s" class="mgr-carousel">', $hash);
do_action('mgr_inside_top');
$images = get_field('mgr_gallery', $atts['id']);
$target = $atts['linksnewwindow'] ? '_blank' : '_self';
if ( $images ):
foreach( $images as $image ):
$getlink = $image['description'];
$getimg = $image['sizes'][$atts['imgsize']];
$getlbimg = $image['sizes']['large'];
$getalt = $image['alt'];
$getcap = $image['caption'];
$caption = $getcap ? sprintf('<div class="mgr-caption">%s</div>', $getcap) : false;
if ($atts['lightbox']){
$theimage = sprintf('<a class="mgr-group-%s" rel="mgr-group" href="%s" target="%s">%s<img src="%s" alt="%s" /></a>',$hash,$getlbimg,$target,$caption,$getimg,$getalt);
} else {
$theimage = ($image['description']) ?
sprintf('<a href="%s" target="%s">%s<img src="%s" alt="%s" /></a>',$getlink,$target,$caption,$getimg,$getalt)
: sprintf('%s<img src="%s" alt="%s" />',$caption,$getimg,$getalt);
}
$out .= apply_filters('mgr_item_output',sprintf('<div class="item">%s</div>',$theimage));
endforeach;
endif;
do_action('mgr_inside_bottom');
$out .= sprintf('</div>');
do_action('mgr_after');
return apply_filters('mgr_output',$out);
}
}
new baMaryGoRoundSC;