将猫头鹰旋转木马整合到Wordrpess中

时间:2016-06-16 14:28:38

标签: javascript jquery wordpress owl-carousel

配偶,我无法将Owl Carousel整合到我的Wordpress网站中。我的页面上没有看到旋转木马。谢谢!

我的functions.php代码:

function templatename_add_owlcarousel() {
wp_enqueue_script ( 'jquery' );

wp_enqueue_script( 'owlcarousel', get_template_directory_uri() . '/assets/js/owl.carousel.min.js', array( 'jquery' ), false, true );
wp_enqueue_script( 'owl-carousel', get_template_directory_uri() . '/assets/js/owl.carousel-init.js', array( 'jquery' ), false, true );
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/assets/css/owl.carousel.css' );
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/assets/css/owl.theme.default.min.css' );
}
add_action( 'wp_enqueue_scripts', 'templatename_add_owlcarousel' );

owl.carousel.init.js代码:

$(document).ready(function() {

  $("#owl-demo").owlCarousel({

      autoPlay: 3000, //Set AutoPlay to 3 seconds

      items : 4,
      itemsDesktop : [1199,3],
      itemsDesktopSmall : [979,3]

  });

});

index.php部分,代码为:

<div id="owl-demo" class="owl-carousel owl-theme">
  <div class="item"><h1>1</h1></div>
  <div class="item"><h1>2</h1></div>
  <div class="item"><h1>3</h1></div>
  <div class="item"><h1>4</h1></div>
  <div class="item"><h1>5</h1></div>
  <div class="item"><h1>6</h1></div>
  <div class="item"><h1>7</h1></div>
  <div class="item"><h1>8</h1></div>
  <div class="item"><h1>9</h1></div>
  <div class="item"><h1>10</h1></div>
  <div class="item"><h1>11</h1></div>
  <div class="item"><h1>12</h1></div>
  <div class="item"><h1>13</h1></div>
  <div class="item"><h1>14</h1></div>
  <div class="item"><h1>15</h1></div>
  <div class="item"><h1>16</h1></div>
</div>

<div class="customNavigation">
  <a class="btn prev">Previous</a>
  <a class="btn next">Next</a>
  <a class="btn play">Autoplay</a>
  <a class="btn stop">Stop</a>
</div>

我的文件结构是:

TEMPLATENAME /资产/ CSS /

  • owl.carousel.css
  • owl.carousel.min.css
  • owl.theme.default.min.css

TEMPLATENAME /资产/ JS /

  • owl.carousel.min.js
  • owl.carousel.js
  • owl.carousel-init.js

2 个答案:

答案 0 :(得分:2)

你的footer.php代码在哪里?你没忘记把你的初始代码放到你的footer.php文件中吗?

<script src="<?php bloginfo('template_directory'); ?>/js/owl.carousel-init.js"></script>

<script src="<?php bloginfo('template_directory');>/js/owl.carousel.min.js"></script> 

答案 1 :(得分:0)

wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri() . '/assets/css/owl.carousel.css' );
wp_enqueue_style( 'owlcarousel-style', get_template_directory_uri. '/assets/css/owl.theme.default.min.css' );

问题是您为两个CSS文件都放置了相同的句柄名称