WordPress uses jquery to implement a dynamic drop-down menu

Source: Internet
Author: User
Tags jquery library

First, you need to create a menu for your site, which can be achieved through the WordPress management background-appearance-menu bar. To display the created menu on the page, you need to perform the following steps:

Open the FUNCTION. Php file of your topic and add the following code to it,

The code is as follows: Copy code

Register_nav_menus ();
Wp_nav_menu (array ('menu '= & gt; 'mymenu', 'dest' = & gt; 1 ));

Use the register_nav_menus () function to register a menu. It also supports registration of multiple menus.

Then you can display menus on the page, such as HTML

WORDPRESS
It allocates the corresponding class to the LI in the menu. It is not difficult to find that the current page is allocated with. current-menu-item. The current article is classified as. current-post-ancestor ..
So we can add the CSS style you want to these classes directly. It's very easy ..

The code is as follows: Copy code

. Current-post-ancestor a,. current-menu-parent a,. current-menu-item a,. current_page_item {
Color: green;
}

This is OK. For the effect, see the menu of this website. It seems like nonsense...

Level 2 drop-down menu

The second-level menu section of the original css display is as follows:

The code is as follows: Copy code
# Access ul li: hover> ul {display: block ;}

Even because the jQuery library has been added to the blog, it is easy to implement the dynamic drop-down menu effect and add the code:

The code is as follows: Copy code
JQuery (document). ready (function ($ ){
$ ('# Access ul li'). hover (function (){
$ ('Ul ', this). slideDown (300)
},
Function (){
$ ('Ul ', this). slideUp (300)
})
});

The second-level menu after Jquery can be dynamically displayed in ie6, ie7, ie8, and firefox

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.