jQuery无法在WordPress 3.5中运行

所以我似乎有一个旧的Wordpress主题的问题。 我只是将我的一个主题从黑暗中带出来作为我的投资组合的一部分,并立即意识到我的jQuery侧边栏已完全停止工作,我不知道为什么。 现在请注意,在WordPress实现他们自己的“自定义”侧边栏实现之前,我写了一些侧边栏代码(所以我非常不确定这是否与此有关但是非常怀疑它。我认为我是在Wordpress 3.1的时候开发的) 。 故障的具体代码位于此处

      $(document).ready(function() { $(".button-slide").click(function() { $("#slide-panel").slideToggle("slow"); }); });   

我知道jQuery版本已经过时了,但即使在更新之后我仍然没有成功。 有没有人知道我做错了什么。 如果需要,我很乐意提供更多代码。 以上所有内容都位于我主题中的header.php文件中。

这是实施的一部分

 

和一些CSS

  #navigation-block { position:relative; /*top:100px; left:100px;*/ } #hide { position:absolute; top:30px; left:-190px; } ul#sliding-navigation { list-style: none; /*font-size: .75em;*/ font-size: 1em; /*margin: 30px 0;*/ padding: 0; width: 175px; } ul#sliding-navigation li.sliding-element h3, ul#sliding-navigation li.sliding-element a { display: block; width: 175px; padding: 5px 10px; margin: 0; margin-bottom: 5px; /* corner code */ /*border-bottom-right-radius: 50px; border-top-right-radius: 50px; border-top-left-radius: 50px; -moz-border-radius-topright: 50px; -moz-border-radius-topleft: 50px; -moz-border-radius-bottomright: 50px;*/ -moz-border-radius: 1em 4em 1em 4em; border-radius: 1em 4em 1em 4em; border: outset; } 

sliding_effect.js

 $(document).ready(function() { slide("#sliding-navigation", 25, 15, 150, .8); }); function slide(navigation_id, pad_out, pad_in, time, multiplier) { // creates the target paths var list_elements = navigation_id + " li.sliding-element"; var link_elements = list_elements + " a"; // initiates the timer used for the sliding animation var timer = 0; // creates the slide animation for all list elements $(list_elements).each(function(i) { // margin left = - ([width of element] + [total vertical padding of element]) $(this).css("margin-left","-180px"); // updates timer timer = (timer*multiplier + time); $(this).animate({ marginLeft: "0" }, timer); $(this).animate({ marginLeft: "15px" }, timer); $(this).animate({ marginLeft: "0" }, timer); }); // creates the hover-slide effect for all link elements $(link_elements).each(function(i) { $(this).hover( function() { $(this).animate({ paddingLeft: pad_out }, 150); }, function() { $(this).animate({ paddingLeft: pad_in }, 150); }); }); } 

您确定在同一页面上包含2个不同版本的jQuery不会导致任何问题吗?

WordPress附带的jQuery版本(在调用wp_head();时可能包含它)在无冲突模式下加载。 这在这里解释:

基本上你需要用你的脚本包装

 jQuery(document).ready(function($) { // $() will work as an alias for jQuery() inside of this function });