Wordpress中的Twitter Bootstrap Carousel不会自动启动

时间:2013-09-17 11:29:04

标签: php jquery wordpress twitter-bootstrap carousel

我正在尝试使用自定义的Twitter Bootstrap主题在Wordpress上运行一个网站。

我一直在寻找与他们的答案类似的问题,但我似乎无法让主页上的旋转木马自动启动。点击左/右箭头后它会开始滑动,但我认为仍然有问题,因为即使我将滑动间隔设置为500,它似乎也不是这样。我想它一定是我遗失的非常基本的东西。

是我加载的脚本序列(与functions.php相关):

<?php 
function wpbootstrap_scripts_with_jquery()
{
    // Register the script like this for a theme:
    wp_register_script( 'custom-script', get_template_directory_uri() . '/bootstrap/js/bootstrap.js', array( 'jquery' ) );
    // For either a plugin or a theme, you can then enqueue the script:
    wp_enqueue_script( 'custom-script' );
}
add_action( 'wp_enqueue_scripts', 'wpbootstrap_scripts_with_jquery' );

if ( function_exists('register_sidebar') )
    register_sidebar(array(
        'before_widget' => '',
        'after_widget' => '',
        'before_title' => '<h3>',
        'after_title' => '</h3>',
    ));
?>

怎么样?
<?php wp_enqueue_script("jquery"); ?>

参与header.php?

或者只是

中的一个基本错误
<script type="text/javascript">

    $(document).ready(function() {
        $('#myCarousel').carousel({
        interval: 500
        });

        $('#myCarousel').carousel('cycle');

    });

</script>

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:0)

您必须先加载bootstrap.js才能在内联脚本中调用carousel()

<script src="http://thirdwavepower.com/V2/wp-content/themes/wpbootstrap/bootstrap/js/bootstrap.js?ver=3.5.2"></script>

<script type="text/javascript">
    $(document).ready(function() {
        $('#myCarousel').carousel({
            interval: 500
        }); 
        $('#myCarousel').carousel('cycle');
    });
</script>

答案 1 :(得分:0)

有时您需要将JavaScript文件放在carousal之后。实际上在页面结束之前。

<script type="text/javascript">
var $ = jQuery.noConflict();
$(document).ready(function() { 
$('#myCarousel').carousel({ interval: 3000, cycle: true });
}); 

参考:http://twitterbootstrap.org/twitter-bootstrap-3-carousel-not-automatically-starting/

感谢