自定义帖子类型owl滑块正常显示,我正在创建自定义帖子类型并使用owl轮播滑块寄存器功能,但短代码循环正常工作..
自定义猫头鹰滑块短代码
function custom_owl($para,$content){
$para = shortcode_atts ( array(
'' => '',
), $para);ob_start();
$cutting_slider = null;
$cutting_slider = new WP_Query( array ('post_type' => 'custom_cuttingsystem','posts_per_page' => -1,'orderby' => 'rand'));
if($cutting_slider->have_posts()) {
while ( $cutting_slider->have_posts()) {
$cutting_slider->the_post(); ?>
<div class="owl-carousel owl-theme">
<div class="item">
<?php the_post_thumbnail ();?>
<a href="<?php the_permalink() ?>">
<h4><?php the_title(); ?></h4></a>
<span><?php the_category(); ?></span>
</div></div>
<?php }}
wp_reset_postdata();
$cutting_slider = null; return ob_get_clean();
}
add_shortcode ('owl-slider','custom_owl');
CUSTOM JS
$(document).ready(function() {
$(".owl-carousel").owlCarousel({
autoPlay: 3000, //Set AutoPlay to 3 seconds
items: 4,
itemsDesktop: [1199, 3],
itemsDesktopSmall: [979, 3]});});
注册子主题owl函数入队脚本
function custom_owlcarousel() {
wp_enqueue_style('owlmin-css', get_stylesheet_directory_uri().'/owl/owl.carousel.min.css', 'all');
wp_enqueue_style('owldefault', get_stylesheet_directory_uri().'/owl/owl.theme.default.min.css', 'all');
wp_enqueue_script('carousel-js', get_stylesheet_directory_uri().'/owl/owl.carousel.js', array('jquery'), NULL, true);
// wp_enqueue_script('owl-jq', get_stylesheet_directory_uri().'/owl/jquery.min.js', array('jquery'), NULL, true);
}
add_action( 'wp_enqueue_scripts', 'custom_owlcarousel' );