Created
January 20, 2018 06:03
-
-
Save rashed-amin/47e856dc0823fbcaf5f8338db01e9365 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if ( ! defined( 'ABSPATH' ) ) { exit; } | |
function consulto_slides_shortcode($atts){ | |
extract( shortcode_atts( array( | |
'count' => '3', | |
'arrows' => 'true', | |
'dots' => 'false', | |
'autoplay' => 'true', | |
'autoplay_time' => '5000', | |
'slide_id' => '', | |
), $atts) ); | |
if($count == 1) { | |
$q = new WP_Query( array('posts_per_page' => 1, | |
'post_type' => 'slide', | |
'p' => $slide_id) ); | |
} else { | |
$q = new WP_Query( array('posts_per_page' => $count, | |
'post_type' => 'slide') ); | |
} | |
$list = ''; | |
if($count != 1) { | |
$list .= ' | |
<script> | |
jQuery(window).load(function(){ | |
jQuery("#consulto-slides-'.esc_attr($slide_id).'").owlCarousel({ | |
items: 1, | |
loop: true, | |
autoplay: '.esc_attr($autoplay).', | |
dots: '.esc_attr($dots).', | |
nav: '.esc_attr($arrows).', | |
autoplayTimeout: '.esc_attr($autoplay_time).', | |
navText: ["<i class=\'fa fa-angle-left\'></i>", "<i class=\'fa fa-angle-right\'></i>"], | |
autoplayHoverPause: false, | |
touchDrag: false, | |
mouseDrag: false, | |
smartSpeed: 700 | |
}); | |
jQuery("#consulto-slides-'.esc_attr($slide_id).'").on("translate.owl.carousel", function () { | |
jQuery(this).find(".owl-item .consulto-slide-text > *").removeClass("fadeInLeft animated").css("opacity","0"); | |
jQuery(this).find(".owl-item .consulto-slide-st-img").removeClass("fadeInRight animated").css("opacity","0"); | |
}); | |
jQuery("#consulto-slides-'.esc_attr($slide_id).'").on("translated.owl.carousel", function () { | |
jQuery(this).find(".owl-item.active .consulto-slide-text > *").addClass("fadeInLeft animated").css("opacity","1"); | |
jQuery(this).find(".owl-item.active .consulto-slide-st-img").addClass("fadeInRight animated").css("opacity","1"); | |
}); | |
}); | |
</script>'; | |
} | |
$list .=' | |
<div class="slider-preloader-wrap"> | |
<div class="preloader-wrap"><div class="spinner2"></div></div> | |
<div class="consulto-slides" id="consulto-slides-'.esc_attr($slide_id).'">'; | |
while($q->have_posts()) : $q->the_post(); | |
$idd = get_the_ID(); | |
if(get_post_meta($idd, 'consulto_slide_meta', true)) { | |
$slide_meta = get_post_meta($idd, 'consulto_slide_meta', true); | |
} else { | |
$slide_meta = array(); | |
} | |
if(array_key_exists('enable_overlay', $slide_meta)){ | |
$enable_overlay = $slide_meta['enable_overlay']; | |
}else{ | |
$enable_overlay = true; | |
} | |
if(array_key_exists('overlay_percentage', $slide_meta)){ | |
$overlay_percentage = $slide_meta['overlay_percentage']; | |
}else{ | |
$overlay_percentage = .7; | |
} | |
if(array_key_exists('overlay_color', $slide_meta)){ | |
$overlay_color = $slide_meta['overlay_color']; | |
}else{ | |
$overlay_color = '#181a1f'; | |
} | |
$consulto_allowed_html_in_slide = array( | |
'a' => array( | |
'href' => array(), | |
'class' => array(), | |
'target' => array(), | |
), | |
'img' => array( | |
'href' => array(), | |
'class' => array(), | |
'alt' => array(), | |
), | |
'p' => array(), | |
'h1' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'h2' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'h3' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'h4' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'h5' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'h6' => array( | |
'class' => array(), | |
'strong' => array(), | |
'b' => array(), | |
), | |
'br' => array(), | |
'strong' => array(), | |
'i' => array(), | |
); | |
$post_content = get_the_content(); | |
$list .= ' | |
<div style="background-image:url('.esc_url(get_the_post_thumbnail_url($idd)).')" class="single-consulto-slide-item" id="single-consulto-slide-item-'.esc_attr($idd).'">'; | |
if($enable_overlay == true){ | |
$list .='<div style="opacity:'.$overlay_percentage.'; background-color:'.$overlay_color.'" class="slide-overlay"></div>'; | |
} | |
$list .=' | |
<div class="consulto-slide-table"> | |
<div class="consulto-slide-tablecell"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-10 col-md-offset-1"> | |
<div class="consulto-slide-text"> | |
<h1>'.esc_html(get_the_title($idd)).'</h1> | |
'.wp_kses(wpautop($post_content), $consulto_allowed_html_in_slide).''; | |
if(array_key_exists('buttons', $slide_meta) && $slide_meta['buttons']) { | |
$list .=' | |
<div class="consulto-slide-buttons">'; | |
foreach($slide_meta['buttons'] as $button) { | |
if($button['linkto'] == 1) { | |
$btn_link_markup = get_page_link($button['to_page']); | |
} else { | |
$btn_link_markup = $button['to_external']; | |
} | |
$list .='<a target="'.$button['tab'].'" href="'.esc_url($btn_link_markup).'" class="consulto-btn btn_effect '.esc_attr($button['type']).'-btn">'.esc_html($button['btn_text']).' <i class="fa fa-long-arrow-right"></i></a>'; | |
} | |
$list .=' | |
</div>'; | |
} | |
$list .=' | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
'; | |
endwhile; | |
$list.= '</div> </div>'; | |
wp_reset_query(); | |
return $list; | |
} | |
add_shortcode('consulto_slides', 'consulto_slides_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment