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 运筹学中在线排序的时间在线排序的在线LPT算法
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试,帮帮忙吧