Skip to content

Instantly share code, notes, and snippets.

@Rayhanuc
Created October 6, 2018 19:34
Show Gist options
  • Save Rayhanuc/c6c670f70794fccba2b343ca62df6bac to your computer and use it in GitHub Desktop.
Save Rayhanuc/c6c670f70794fccba2b343ca62df6bac to your computer and use it in GitHub Desktop.
//industry_rayhan_slide_shortcode start
function industry_rayhan_slides_shortcode($atts){
extract( shortcode_atts( array(
'count' => 2,
'type' => 'page',
), $atts) );
$arg = array(
'post_type' => 'industry-slide',
'posts_per_page' => 3,
);
$get_post = new WP_Query($arg);
$slider_rendom_number = rand(6982887, 74634636);
$industry_slides = '
<script>
jQuery(window).load(function() {
jQuery("#industry-slides-'.$slider_rendom_number.'").owlCarousel({
items: 1,
loop: true,
dots: true,
nav: true,
navText: ["<i class=\'fa fa-angle-left\'></i>","<i class=\'fa fa-angle-right\'></i>" ],
autoplay: false
});
});
</script>
<div id="industry-slides-'.$slider_rendom_number.'" class="owl-carousel industry-slides">';
while ($get_post->have_posts()) : $get_post->the_post();
$post_id = get_the_ID();
if (get_post_meta($post_id, 'industry_rayhan_slide_meta', true)) {
$slide_meta = get_post_meta($post_id, 'industry_rayhan_slide_meta', true);
}else {
$slide_meta = array();
}
if (array_key_exists('text_color', $slide_meta)) {
$text_color = $slide_meta ['text_color'];
}else {
$text_color = '#333';
}
//enable_overly
if (array_key_exists('enable_overly', $slide_meta)) {
$enable_overly = $slide_meta ['enable_overly'];
}else {
$enable_overly = false;
}
//overly_color
if (array_key_exists('overly_color', $slide_meta)) {
$overly_color = $slide_meta ['overly_color'];
}else {
$overly_color = '#333';
}
//overly_opacity
if (array_key_exists('overly_opacity', $slide_meta)) {
$overly_opacity = $slide_meta ['overly_opacity'];
}else {
$overly_opacity = 70;
}
$industry_slides .= '
<div style="background-image:url('.get_the_post_thumbnail_url($post_id, 'large').')" class = "industry-single-slide" >' ;
if($enable_overly == true) {
$industry_slides .= '<div style="opacity:.'.$overly_opacity.'; background-color:'.$overly_color.'" class="industry-slide-overlay"></div>';
}
$industry_slides .= '
<div class="industry-single-slide-inner">
<div class="container">
<div class="row">
<div style="color:'.esc_attr( $text_color ).'" class="col-md-6">
<h2>'.get_the_title($post_id).'</h2>
'.wpautop(get_the_content($post_id)).'
</div>
</div>
</div>
</div>
</div>
';
endwhile;
$industry_slides .= '</div>';
wp_reset_query();
return $industry_slides;
}
add_shortcode('industry_slides', 'industry_rayhan_slides_shortcode');
//industry_rayhan_slides_shortcode end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment