我在wordpress中制作了一个自定义模板,除featherlight.js以外,其他所有东西都正常运行,该文件在网站的非wordpress版本中有效,但在Wordpress模板中无效。从服务器成功加载了所有文件。现在,图像在新窗口中打开,而不是在灯箱中打开。

featherlight.min.css-由@import url('css/featherlight.min.css');加载到style.css文件中。

featherlight.min.js-在</body>标记-<script src="<?php bloginfo('template_url') ?>/js/featherlight.min.js" type="text/javascript" charset="utf-8"></script>之前加载

图片示例:

<a href="<?php bloginfo('template_url'); ?> /img/ss/scrsht2-big.jpg" data-featherlight="image"><img src="<?php bloginfo('template_url'); ?> /img/scrsht2.jpg" /></a>

最佳答案

我无法发表评论,以下是我认为可以解释您的问题的各种观点。


确保已通过以下方式将脚本排入队列(并且不要忘记jQuery):

<?php

function enqueue_my_scripts() {
    wp_enqueue_script('jquery'); //include jQuery version bundled with Wordpress in your page
    wp_enqueue_style( 'featherlight', get_template_directory_uri() . '/css/featherlight.min.css' );
    wp_enqueue_script('featherlight', get_template_directory_uri() . '/js/featherlight.min.js', array( 'jquery' ) );

}
add_action( 'wp_enqueue_scripts', 'enqueue_my_scripts' );

?>

检查jQuery version bundled with your Wordpress version是否适合您的插件。
捆绑的jQuery在no-conflict mode中运行。确保初始化插件的脚本(如果有的话)在这种模式下可以被理解-基本上使用jQuery代替$details here)。
如果您正在使用子主题,请注意bloginfo('template_url')作为get_template_directory_uri();,请返回指向父主题的链接。在这种情况下,请使用get_stylesheet_directory_uri()

关于javascript - Wordpress自定义模板中的featherlight.js,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26257734/

10-09 23:48