2012-03-16 3 views
0

私はwordpressで働いていました。私はgoogleで見つけました。そして、私を不可解な唯一のものではなく、親リンクはクリック可能持つのサブメニューを展開して許可する親リンクを作成する方法..ですJQuery - 次の親リンクを次のページに移動する代わりに、それ自身のサブリンクを展開する方法を教えてください。

jQuery(document).ready(function() { 

//Hide the submenus 
jQuery('.leftNav_Level2 ul li ul').hide(); 

//If its a page parent (based off wordpress), add the class "displayMe" 
//This way the accordion will be opened up on the page you are on. 
if (jQuery('.leftNav_Level2 ul li').hasClass("current_page_parent")) { 
jQuery('.leftNav_Level2 .current_page_parent ul').addClass("displayMe"); 
jQuery('.leftNav_Level2 .current_page_ancestor > ul').attr('style','display:block'); 
jQuery('.leftNav_Level2 .current_page_parent > ul').attr('style','display:block'); 
} 
jQuery('.leftNav_Level2 .current_page_item > ul').attr('style','display:block'); 


//When you click it, toggle 
jQuery('.leftNav_Level2 ul li a').click(
function() { 

//Onclick Remove the class dipslay me which is only display:block; 
//This way they can close it if they click it or it will glitch 
jQuery(this).next().next().slideToggle('slow').removeClass("displayMe"); 

//return false so the # doenst move view to the top of the page 
if (jQuery(this).attr('href') == '#') { return false; } 

//Close it all out 
}); 
}); 

ワードプレスのテンプレートがあります。

<div class="leftNav_Level2"> 
<ul> 
<?php wp_list_pages('title_li='); ?> 
</ul> 
</div><!--/leftNav_Level1--> 

意志感謝していただきありがとうございますu

+1

'attrの( 'スタイル'、 '表示:ブロック')' ????それはうまくいくかもしれませんが、地獄のように醜いです。あなたはそれのために 'css()'を使うべきです... – elclanrs

+0

私は本当にあなたが望むものを得ることはできませんが、私はあなたがcssで最も効果的にできると思います。 – janw

答えて

0

あなたは問題を解決するにはあまりにも多くのJavaScriptを使用しています。私は、そのためのチュートリアルはここにある(オープン/クローズのサブメニューなど)スタイリングの利用CSS、言う:http://wpguru.co.za/navigation/make-your-own-wordpress-drop-down-menu/

あなたは親ノードがリンクされたページに移動を停止したい場合は、あなたが使用することができます。

jQuery('.leftNav_Level2 ul>li.current_page_ancestor').click(function(e) { 
    e.preventDefault(); 
}); 

また、ここでは詳細はWP 3.0以降の新しいメニューを見てみることができます:http://bavotasan.com/2010/wordpress-3-checking-out-the-new-menu-system/

関連する問題