doqrjrc95405 2016-07-08 09:38
浏览 80

在wordpress中安装bxSlider Jquery插件

I am making my first steps learning to code. I made some courses on Internet an now I decided to build a Wordpress theme so like this I can continue learning from the practice.

I decided to make an image slider, so for this I decided to install a Jquery plugin. I know that I can install a wordpress plugin but I think that it's convenient to learn how to install a Jquery plugin too for many reasons.

I followed these steps to install the bxSlider plugin, but unfortunately there is something that it's not ok and it makes my plugin doesn't work:

1) Functions.php: I loaded all the files that I need

function loadbxslider() {

    wp_enqueue_style('bxstyle', '/jquery.bxslider/jquery.bxslider.css');
    wp_enqueue_script('bxscript', '/jquery.bxslider/jquery.bxslider.min.js', array('jquery'));

}

add_action('init', 'loadbxslider');

2) Header.php: I wrote this before <?php wp_head(); ?>:

<!--?php wp_enqueue_script('jquery'); ?-->
<!--?php wp_head(); ?-->

And this inmediately after <?php wp_head(); ?>:

<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function(){
  jQuery('#slidebx').bxSlider({
    mode: 'horizontal',
    infiniteLoop: true,
    speed: 2000,
    pause: 8000,
    auto: true,
    pager: false,
    controls: true
  });
});
// ]]></script>

So the first part of my header.php is like this:

?><!DOCTYPE html>
<html <?php language_attributes(); ?> class="no-js">
<head>
    <meta charset="<?php bloginfo( 'charset' ); ?>">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="profile" href="http://gmpg.org/xfn/11">
    <?php if ( is_singular() && pings_open( get_queried_object() ) ) : ?>
    <link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">
    <?php endif; ?>


    <!--?php wp_enqueue_script('jquery'); ?-->
    <!--?php wp_head(); ?-->

    <?php wp_head(); ?>


<script type="text/javascript">// <![CDATA[
jQuery(document).ready(function(){
  jQuery('#slidebx').bxSlider({
    mode: 'horizontal',
    infiniteLoop: true,
    speed: 2000,
    pause: 8000,
    auto: true,
    pager: false,
    controls: true
  });
});
// ]]></script>


</script>
</head>

3) bxSlider inside my content: using the id slidebx

<div id="slidebx">
  <div><?php the_field('image1'); ?></div>
  <div><?php the_field('image2'); ?></div>
  <div><?php the_field('image3'); ?></div>
  <div><?php the_field('image4'); ?></div>
  <div><?php the_field('image5'); ?></div>
  <div><?php the_field('image6'); ?></div>
  <div><?php the_field('image7'); ?></div>
  <div><?php the_field('image8'); ?></div>
  <div><?php the_field('image9'); ?></div>
  <div><?php the_field('image10'); ?></div>
</div>

I have a week trying to discover why this plugin doesn't work. If you have some suggestion would be good for my learning process.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 蓝牙耳机怎么查看日志
    • ¥15 Fluent齿轮搅油
    • ¥15 八爪鱼爬数据为什么自己停了
    • ¥15 交替优化波束形成和ris反射角使保密速率最大化
    • ¥15 树莓派与pix飞控通信
    • ¥15 自动转发微信群信息到另外一个微信群
    • ¥15 outlook无法配置成功
    • ¥30 这是哪个作者做的宝宝起名网站
    • ¥60 版本过低apk如何修改可以兼容新的安卓系统
    • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏