Created
October 5, 2017 12:54
-
-
Save nayeemch/77e62d14cb2115e31884856ff2549576 to your computer and use it in GitHub Desktop.
wp_slider main.php
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
function amaderlab_toolkit_include_files(){ | |
wp_enqueue_style('owl-carousel',plugins_url('/assets/css/owl.carousel.min.css',__FILE__)); | |
wp_enqueue_script('owl-carousel',plugins_url('/assets/js/owl.carousel.min.js',__FILE__), array('jquery'),'2.2.1',true); | |
} | |
add_action('wp_enqueue_scripts','amaderlab_toolkit_include_files'); | |
function amaderlab_custom_post() { | |
register_post_type( 'amaderlab-slide', | |
array( | |
'labels' => array( | |
'name' => __( 'Slider' ), | |
'singular_name' => __( 'Slide' ) | |
), | |
'supports' => array('title', 'editor', 'thumbnail', 'page-attributes'), | |
'public' => false, | |
'show_ui' => true | |
) | |
); | |
} | |
add_action('init','amaderlab_custom_post'); | |
// my function | |
function amaderlab_slider_shortcode($atts){ | |
extract(shortcode_atts(array( | |
'count'=> 2, | |
'type'=> 'page', | |
),$atts)); | |
$arg = array('post_type' => 'amaderlab-slide', | |
'posts_per_page' => 2 | |
); | |
$get_post = new WP_Query($arg); | |
$slide_random_number_generator = rand(1021,10021); | |
$slider_markup = ' | |
<script> | |
jQuery(window).load(function(){ | |
jQuery("#amaderlab-slides-'.$slide_random_number_generator.'").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="amaderlab-slides-'.$slide_random_number_generator.'" class="owl-carousel amaderlab-slides">'; | |
while ($get_post -> have_posts()) : $get_post -> the_post(); | |
$post_id = get_the_ID(); | |
$slider_markup .= ' | |
<div style="background-image:url('.get_the_post_thumbnail_url($post_id ,'large').')" class="amaderlab-slider"> | |
<div class="amaderlab-slider-inner"> | |
<div class="container"> | |
<div class="row"> | |
<div class="col-md-6"> | |
<h2>'.get_the_title($post_id).'</h2> | |
'.wpautop(get_the_content($post_id)).' | |
</div> | |
</div> | |
</div> | |
</div> | |
</div> | |
'; | |
endwhile; | |
$slider_markup .='</div>'; | |
wp_reset_query(); | |
return $slider_markup; | |
} | |
add_shortcode('amaderlab_silder','amaderlab_slider_shortcode'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment