Home  >  Article  >  Backend Development  >  PHP study notes (4), php study notes_PHP tutorial

PHP study notes (4), php study notes_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:58:51834browse

PHP study notes (4), PHP study notes

Some functions in the WordPress framework:

wp_get_nav_menu($default): Get menu based on condition $default, get all menus by default

Where $default defaults to the following:

<span>$default</span> = <span>array</span><span>(
  &lsquo;theme_location&rsquo; </span>=>'',
  'menu' =>'',
  'container' =>'div',
  'container_class' => 'menu-{menu_slug}-container',
  'container_id' =>'',
  'menu_class'=>'menu',
  'echo' => <span>true</span>,
  'fallback_cb'=>'wp_page_menu',
  'before' =>'',
  'after' =>'',
  'link_before' =>'',
  'link_after' =>'',
  'items_wrap' =>'<ul id=''%1s'>%3<span>$s</span></ul>,
  'depth' =>0,
  'walker' =>''<span>
);</span>

Parameter description:

$theme_location: Default is none, specifies a registered navigation menu, if not specified, the first one will be displayed. Such as primary, secondary, etc.

$menu: The default is none. Use the name of the navigation menu to call the menu. You can use attributes such as term_id, slug, name etc.

$container: The default is div, which is the parent node of ul. It only supports div and nav tags. You can also use false to remove the label of the ul parent node

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

$container_id: The default is none, the id of the ul parent node

$menu_class: Default is menu, class attribute of ul node

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

$echo: The default is true, which determines whether to directly display the Korean style navigation menu and return the HTML fragment. If you want to use the navigation code as a skin type, you can set it to false.

$fallback_db: The default value is wp_page_menu, used as a callback function when navigation is not set in the background

$items_wrap: Default is none, use string modification to replace ul's class

$depth: The default is 0, which displays the depth of the menu. When it is 0, it displays menus of all depths

$walker: By default, new Walker_Nav_Menu() is used, a custom traversal object, and a Walker subclass object is called to define the navigation menu.

Use Walker subclass to make a custom menu:

The Walker class is an abstract class that defines how to display navigation, etc. This abstract class contains 4 properties and 6 methods:

Attributes:

$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: Close the element tag output by start_lvl

start_el: Output a start tag for each element

end_el: Close the tag of start_el

(Core) display_element: Define how to display elements in the tree structure

(core) walk loops through each element in the tree structure according to $max_depth

If you need to customize navigation, you can directly write a class to inherit Walker, but this will require rewriting all methods. If the changes are not major, you can directly inherit the Walker_NAV_Menu class and rewrite the classes that need to be modified.

When rewriting display_element, the parameter $element contains all the information of the currently traversed element. For example, you can use $element->object_id to get the term_id of the current element

Code snippet: Use add_shorcode('name','function_name') to generate a code snippet ['name'] in the system, which can be used directly in the WordPress backend article, or use show_shortcode['[ in the code name]']; Directly execute

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1101865.htmlTechArticlePHP study notes (4), php study notes Some functions in the WordPress framework: wp_get_nav_menu($default): According to The condition $default gets the menu, and gets all the menus by default. Among them, $d...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn