Skip to content

Instantly share code, notes, and snippets.

@Galibri
Created October 10, 2017 11:19
Show Gist options
  • Save Galibri/01ba55cbc21270f93896f910f93f107c to your computer and use it in GitHub Desktop.
Save Galibri/01ba55cbc21270f93896f910f93f107c to your computer and use it in GitHub Desktop.
//shrotcode for slider post type query
function apbd_slider_list_shortcode($atts){
extract( shortcode_atts( array(
'count' => 2,
'type' => 'industry-slide'
), $atts) );
$args = array(
'posts_per_page' => $count,
'post_type' => $type
);
$query = new WP_Query( $args );
$slide_random_number = rand(342345, 456547);
$apbd_slide_list = '
<script>
jQuery(window).on( "load", function() {
jQuery("#industry-slides-'.$slide_random_number.'").owlCarousel({
margin: 0,
items: 1,
loop: true,
dots: true,
nav: true,
navText: ["<i class=\'fa fa-angle-left\'></i>", "<i class=\'fa fa-angle-right\'></i>"],
autoplay: true,
autoplayTimeout: 70000
});
});
</script>
<div id="industry-slides-'.$slide_random_number.'" class="owl-carousel industry-slides">';
while($query->have_posts()) : $query->the_post();
$p_id = get_the_ID();
$apbd_slide_list .= '
<div style="background-image: url('. get_the_post_thumbnail_url( $p_id, 'full' ) .')" class="industry-single-slide">
<div class="industry-single-slide-inner">
<div class="container">
<div class="row">
<div class="col-md-6">
<h2>'. get_the_title( $p_id ) . '</h2>
'. wpautop( get_the_content( $p_id ) ) .'
</div>
</div>
</div>
</div>
</div>
';
endwhile;
$apbd_slide_list .= '</div>';
wp_reset_query();
return $apbd_slide_list;
}
add_shortcode('apbd_industry_slider', 'apbd_slider_list_shortcode');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment