我想使用Flexslider显示库,如教程中所示:
https://www.advancedcustomfields.com/resources/gallery/
因此,我访问了Flexslider站点并遵循以下步骤:
https://woocommerce.com/flexslider/
我应该把这个代码放在哪里?
<!-- Place somewhere in the <head> of your document -->
<link rel="stylesheet" href="flexslider.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="jquery.flexslider.js"></script>
我试着上传flexslider。css文件和和jquery。flexslider。js通过FTP连接到我网站的根文件夹,然后我转到标题。我的主题(Divi)的php文件,我这样调用它们:
<?php wp_head(); ?>
<!-- Place somewhere in the <head> of your document -->
<link rel="stylesheet" href="http://electives-abroad.org/flexslider.css" type="text/css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"></script>
<script src="http://electives-abroad.org/jquery.flexslider.js"></script>
</head>
结果是,我没有得到滑块,我的网站的所有图片都消失了。如何才能正确执行?
这就是我将代码放在标题上时发生的情况。php,我网站上的大多数图片都不可见,控制台会抛出以下内容:
Uncaught TypeError: n(...).on is not a function
at Object.<anonymous> (n2.min.js?1552618971:1)
at n2.min.js?1552618971:1
at N2Deferred._doCallbacks (n2.min.js?1552618971:1)
at N2Deferred.resolve (n2.min.js?1552618971:1)
at s (n2.min.js?1552618971:1)
at N2Deferred._doCallbacks (n2.min.js?1552618971:1)
at N2Deferred.resolve (n2.min.js?1552618971:1)
at n2.min.js?1552618971:1
at N2Deferred._doCallbacks (n2.min.js?1552618971:1)
at N2Deferred.then (n2.min.js?1552618971:1)
custom.js?ver=5.1.1:162 Uncaught TypeError: SFSI(...).on is not a function
at custom.js?ver=5.1.1:162
custom.js?ver=3.0.65:1318 Uncaught TypeError: $(...).on is not a function
at custom.js?ver=3.0.65:1318
at custom.js?ver=3.0.65:1418
smartslider-frontend.min.js?1552619634:1 Uncaught TypeError: this.sliderElement.on is not a function
at t.SmartSliderAbstract.onSliderHasDimension (smartslider-frontend.min.js?1552619634:1)
at Object.g (jquery.min.js:16)
at Object.resolveWith (jquery.min.js:16)
at Object.done (jquery.min.js:16)
at t.SmartSliderAbstract.waitForDimension (smartslider-frontend.min.js?1552619634:1)
at t.SmartSliderAbstract.onSliderExists (smartslider-frontend.min.js?1552619634:1)
at Object.g (jquery.min.js:16)
at Object.resolveWith (jquery.min.js:16)
at Object.resolve (jquery.min.js:16)
at s (smartslider-frontend.min.js?1552619634:1)
VM212:1 Unchecked runtime.lastError: Could not establish connection. Receiving end does not exist.
*更新
我在函数中包含了flexslider css和js。php如下所示:
function call_custom_scr_styles() {
wp_enqueue_style( \'flexslider-style\', get_template_directory_uri() . \'http://electives-abroad.org/flexslider.css\' );
wp_enqueue_script( \'jquery-custom\', \'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\', array(), \'1.0.0\', true );
wp_enqueue_script( \'flexslider-script\', \'http://electives-abroad.org/jquery.flexslider.js\', array(), \'1.0.0\', true );
}
add_action( \'wp_enqueue_scripts\', \'call_custom_scr_styles\' );
我也有同样的问题。有些照片从家里消失了:
http://electives-abroad.org/
SO网友:Vishwa
在wordpress中,您应该始终使用排队来包含脚本和样式。
查找函数。php文件在您的主题中,转到末尾并添加以下内容
function call_custom_scr_styles() {
wp_enqueue_style( \'flexslider-style\', get_template_directory_uri() . \'/css/flexslider.css\' );
wp_enqueue_script( \'jquery-custom\', \'https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js\', array(), \'1.0.0\', true );
wp_enqueue_script( \'flexslider-script\', \'http://electives-abroad.org/jquery.flexslider.js\', array(), \'1.0.0\', true );
}
add_action( \'wp_enqueue_scripts\', \'call_custom_scr_styles\' );
note: 我以为你有flexslider。主题目录/css文件夹中的css文件。如果没有,请更改位置
在这种情况下,为什么会出现错误,因为浏览器无法正确呈现所需的内容和资源。您应该首先包括jQuery,因为flexSlider的脚本依赖于jQuery。然后你说你用ftp把css文件上传到你的网站上,但你没有这么叫,而是把你的flexslider css从http://electives-abroad.org/flexslider.css.
确保您的所有资源都可用,并且浏览器能够加载/渲染所有内容。
类型错误:$(…)。on不是一个函数,因为脚本中使用的$符号没有定义。可能是因为jQuery错误。可能未正确包含或JS冲突。
未捕获类型错误:此。滑块。打开并不是一个函数,因为浏览器不知道该怎么做。滑块。调用on(开)。如前所述,flexslider需要jQuery,为此,jQuery应该在加载flexslider脚本之前加载。