开发者

'Galleria' In WordPress- $ is not a function

Trying to get Galleria script working in WordPress? I am have enqueued the script with this code, and it appears to be loading ok:

function add_scripts(){
// Load Galleria

wp_register_script('galleria',get_bloginfo('wpurl').'/galleria/galleria-1.2.2.min.js',array('jquery'),false);
wp_enqueue_script('galleria');
}
add_action('init','add_scripts');

In the post body I have the following, but all I get is the list of images:

<div id="gallery"><img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" />
<img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" />
<img src="http://farm4.static.flickr.com/3316/3532175582_91f984df47.jpg" alt="" /></div>
<script type="text/javascript">
            Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
            $("#gallery").galleria({
                width: 500,
                height: 500
            });</script>

The error I receive is this: $ is not a function ... so the galleria script isn't firing right, or in the right order..

I have asked the question in the Galleria forum as well.

Thanks

This is the basic setup for Galleria, taken right from the documentation, which works fine as standalone html:

<!doctype html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script>
        <script src="galleria/galleria-1.2.2.min.js"></script>
    </head>
    <body>
        <div id="gallery">
            <img src="photo1.jpg">
            <img src="photo2.jpg">
            <img src="photo3.jpg">
        </div>
        <script>
          开发者_运维技巧  Galleria.loadTheme('galleria/themes/classic/galleria.classic.min.js');
            $("#gallery").galleria({
                width: 500,
                height: 500
            });
        </script>
    </body>
</html>


Try replacing $("#gallery") with jQuery("#gallery")

According to this post, Wordpress reserves $ for Prototype.


For some reason, sometimes with wordpress you gotta do like this:

var $ = jQuery;

Or do what @zxt suggested. That should work too. The version of jQuery they use doesn't declare $ variable to avoid conflicts if you are using other libraries that may use $.


You need to include the jquery library in your page -- jquery is what defines "$".

Something like

<script type="text/javascript" src="someplace/on/your/server/jquery.js"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜