WordPress Registration Menu and Call menu methods to explain _php skills

Source: Internet
Author: User

Register_nav_menus () (Register menu)
Register_nav_menus () function is used to register a menu, the menu refers to the WordPress 3.0+ menu manager, after registering the user can be in the menu manager drag generated navigation menu.

Usage

Register_nav_menus ($locations);

Parameters

$locations

(array) (must) to register the menu, the key value is the menu ID, the key name is the menu name, you can create multiple.

Default value: None

return value

The function has no return value.

Example

/**
  * Create Menu
  *http://www.endskin.com/register_nav_menus/* *
function Bing_register_nav_menus () {
  Register_nav_menus ('
    header_menu ' => __ (' top menu ', ' Bing '),
    ' Footer_menu ' => __ (' Footer menu ', ' Bing '))
  ;
}
Add_action (' init ', ' bing_register_nav_menus ');

Other

This function is located at: wp-includes/nav-menu.php


Wp_nav_menu () (menu call)
here's how to invoke the user to add a good menu.

The call menu mainly uses the Wp_nav_menu () function, the Wp_nav_menu () function's parameter is quite many, therefore the function is very formidable, here will one explanation.

Usage

Wp_nav_menu ($args);

Parameters

Parameter has only one $args, but this is an array, by adding parameters to the array, you can customize more details, the bottom is the default value:


$defaults = Array (
  ' theme_location ' => ', '
  menu '      => ', '
  container '    => ' div ',
  ' Container_class ' => ',
  ' container_id '  => ', ' menu_class ' => '   menu ',
  ' menu_id '     => ',
  ' echo '      => true,
  ' FALLBACK_CB '   => ' wp_page_menu ',
  ' before '     = > ',
  ' after '      => ', '
  link_before '   => ', '
  link_after '   =>
  ', ' Items_wrap '   => ' <ul id= '%1 $ S ' class= '%2$s ' >%3$s</ul> ',
  ' depth ' =>      0,
  ' Walker '     => '
);
Wp_nav_menu ($defaults);

Detailed

Theme_locaton

(optional) The name of the menu to invoke, such as Header_menu, which, if not specified, displays the first registered menu by default.

Default value: None

Menu

(optionally) invoke the menu using the name of the navigation menu, which can be an ID, an alias, and a name (in order).

Default value: None

Container

(string) (optional) Navigation menu container type, only support div and nav tags, if the other value, the UL parent node label will not be displayed. It can also be set to False to remove the UL parent node.

Default value: div

Container_class

(optional) The class attribute of the UL parent node.

Default value: Menu-{menu Slug}-container

container_id

(optional) The id attribute of the UL parent node.

Default value: None

Menu_class

(optional) The class attribute of the UL node.

Default value: None

menu_id

(optional) The id attribute of the UL node.

Default Value: Menu Alias

Echo

(Boolean) (optional) returns the Html code for the navigation menu or direct printout, set to False if you want to save the navigation menu code in a variable.

Default value: True (direct print output)

Fallback_cb

(callback function) (optional) The default content that is displayed when this menu is not set in the background.

Default value: Wp_page_menu

Before

(optionally) the text to display before each menu link.

Default value: None

After

(optionally) displays the text after each menu link.

Default value: None

Link_before

(optionally) the text that appears before each menu-linked text.

Default value: None

Link_after

(optionally) the text that appears after each menu link text.

Default value: None

Items_wrap

(optional) Replace the UL class attribute.

Default value: None

Depth

(optional)

Displays the depth of the menu when the value is 0 o'clock to show all the depth of the menu.

Default value: 0

Walker

(object) (optional) The structure object of the menu.

Default value: New Walker_nav_menu

Example

<?php Wp_nav_menu (Array (' theme_location ' => ' header_menu ', ' container ' => false, ' items_wrap ' => ') <ul id= "Topmenu" >%3$s</ul> ', ' FALLBACK_CB ' => ' bing_menu_null_fallback ');?>

Other

This function is located at: wp-includes/nav-menu-template.php

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.