PHP study notes (4), php study notes _ PHP Tutorial

Source: Internet
Author: User
PHP study notes (4): php study notes. PHP learning notes (4): some functions in the Wordpress framework of php learning notes: wp_get_nav_menu ($ default): obtain the menu according to the condition $ default, by default, all menus are obtained, including $ d PHP learning notes (4) and php learning notes.

Some functions in the Wordpress framework:

Wp_get_nav_menu ($ default ):Obtain menus based on the condition $ default. all menus are obtained by default.

$ Default is shown as follows by default:

$default = array(  ‘theme_location’ =>'',  'menu' =>'',  'container' =>'p',  'container_class' => 'menu-{menu_slug}-container',  'container_id' =>'',  'menu_class'=>'menu',  'echo' => true,  'fallback_cb'=>'wp_page_menu',  'before' =>'',  'after' =>'',  'link_before' =>'',  'link_after' =>'',  'items_wrap' =>'
 
 
    %3$s
, 'depth' =>0, 'walker' =>'');

Parameter description:

$ Theme_location: The default value is none. it specifies a registered navigation menu. if not specified, the first menu is displayed. Such as primary and secondary

$ Menu: the default value is none. you can use the name of the navigation menu to call the menu.

$ Container: The default value is p, which is the parent node of ul. only the p and nav labels are supported. you can also use false to remove the ul parent node label.

$ Container_class: The default value is menu-{menu_slug}-container, which is the class attribute of the ul parent node.

$ Container_id: The default value is none. id of the ul parent node

$ Menu_class: default value: menu, class attribute of ul node

$ Menu_id: The default value is menu slug. the id attribute value of the self-increasing ul node

$ Echo: The default value is true. if you want to use the code of the navigation as skin type, you can set it to false.

$ Fallback_db: The default value is wp_page_menu, which is a callback function called when navigation is not set in the background.

$ Items_wrap: The default value is none. replace ul's class with string modification.

$ Depth: The default value is 0. the hierarchical depth of the menu is displayed. if the value is 0, all menus in depth are displayed.

$ Walker: by default, new Walker_Nav_Menu () is used to customize the traversal object and call a Walker subclass object to define the display navigation menu.

Use the Walker subclass to create a custom menu:

The Walker class is an abstract class that defines how to display navigation and so on. this abstract class contains four attributes and six methods:

Attribute:

$ Tree_type, $ db_fields, $ max_pages, $ has_children

Method:

Start_lvl: This method is executed when the Walker class reaches the top level of the structure and can be used to output the start element.

End_lvl: disable element labels output by start_lvl.

Start_el: outputs a start label for each element.

End_el: disable the start_el label.

(Core) display_element: defines how to display elements in a tree structure

(Core) the walk uses $ max_depth to cycle every element in the tree structure.

If you need to customize the navigation, you can directly write a class to inherit Walker, but in this way, you need to override all methods. If the modification is not large, you can directly inherit the Walker_NAV_Menu class and rewrite the class to be modified.

When you override display_element, the parameter $ element contains all information about the elements Currently traversed. for example, you can use $ element-> object_id to obtain the term_id of the current element.

Code snippet: using add_shorcode ('name', 'function _ name'), you can generate a code snippet ['name'] in the system, which can be directly used in wordpress background articles, or use show_domaincode ['[name]'] in the code to directly execute

Http://www.bkjia.com/PHPjc/1101865.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1101865.htmlTechArticlePHP learning notes (4), php learning notes Wordpress framework in some functions: wp_get_nav_menu ($ default): According to the condition $ default get menu, by default get all menu where $ d...

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.