doulian5857 2013-03-31 19:48
浏览 152
已采纳

自定义Wordpress主题 - fancybox无法正常工作?

(Wordpress 3.5.1)

Hi, in functions.php I've included following:

function add_lightbox_cys() {
    wp_enqueue_script( 'jquery' );
    wp_enqueue_script( 'fancybox', get_template_directory_uri() . '/inc/lightbox/js/jquery.fancybox.pack.js', array( 'jquery' ), false, true );
    wp_enqueue_script( 'lightbox', get_template_directory_uri() . '/inc/lightbox/js/jquery.lightbox.js', array('fancybox'), false, true );
    wp_enqueue_script( 'lightbox-style', get_template_directory_uri() . '/inc/lightbox/css/jquery.fancybox.css' );
}
add_action( 'wp_enqueue_scripts', 'add_lightbox_cys');

and then created the lightbox.js with following code:

(function($) { $(".fancybox").fancybox(); })(jQuery);

now in the wordpress theme twentytwelve which came with wordpress this actually works opening pictures in a fancybox.

But when I try this in my own custom made theme it does not trigger the fancybox at all.

here the link to the site: http://goo.gl/y6qfb

can anybody help me?

  • 写回答

2条回答 默认 最新

  • douhuanbai6729 2013-03-31 20:18
    关注

    You can start with this checklist (may not be everthing) :

    1). Your page doesn't have a proper DOCTYPE (don't ask me why), you can fix that in your new theme template.

    2). You don't seem to be using lightbox so remove this reference

    wp_enqueue_script( 'lightbox', get_template_directory_uri() . '/inc/lightbox/js/jquery.lightbox.js', array('fancybox'), false, true );
    

    3). You are loading fancybox css stylesheet as script, hence the error

    Timestamp: 31/03/2013 1:14:48 PM
    Error: SyntaxError: syntax error
    Source File: http://jarsis.de/tground/wp-content/themes/cys/inc/lightbox/css/jquery.fancybox.css?ver=3.5.1
    Line: 2
    Source Code: .fancybox-wrap, 
    

    ... so you would need to replace this line :

    wp_enqueue_script( 'lightbox-style', get_template_directory_uri() . '/inc/lightbox/css/jquery.fancybox.css' );
    

    by this :

    wp_enqueue_style( 'lightbox-style', get_template_directory_uri() . '/inc/lightbox/css/jquery.fancybox.css' );
    

    ... but it depends on how you registered the new stylesheet.

    4). You may need to wrap your fancybox initialization code inside the .ready() method like :

    (function($) { 
      $(function(){
         $(".fancybox").fancybox();
      });
    })(jQuery);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵