Mục menu hoạt động PHP

Tôi đã nghiên cứu và thử RẤT NHIỀU thứ nhưng không có kết quả...Tôi chỉ muốn thiết lập động một lớp 'hoạt động' dựa trên url của trang

Bản mới nhất tôi đã thử có vẻ rất rõ ràng và súc tích nhưng không được – http. //www. siphon-tiếp thị. com/nav-test/nav-test. html

Ai đó có thể VUI LÒNG giúp đỡ?

len

24 Tháng Tư, 2017 lúc 10. 44 giờ chiều

Beverleyh

người tham gia

buồn cười bạn nên hỏi. Chỉ cần viết điều này vào thứ Sáu http. //Blog. fofwebdesign. đồng. uk/40-highlight-the-menu-button-for-the-current-web-page

25 Tháng Tư, 2017 lúc 3. 40 giờ sáng

Atelierbram

người tham gia

@beverleyh đã đánh dấu. ;]


@lprintz có lỗi javaScript, hiển thị nếu bạn mở bảng điều khiển trong DevTools. jQuery không được bao gồm

Nhưng bên cạnh các giải pháp javaScript, có nhiều cách hơn để lột da con mèo này khi sử dụng kết xuất phía máy chủ, chẳng hạn như trong PHP [các khung công tác PHP như WordPress sẽ đặt lớp

wp_nav_menu[ array[
	'menu'   => 'Something custom walker',
	'walker' => new WPDocs_Walker_Nav_Menu[]
] ];

/**
 * Custom walker class.
 */
class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {

	/**
	 * Starts the list before the elements are added.
	 *
	 * Adds classes to the unordered list sub-menus.
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int    $depth  Depth of menu item. Used for padding.
	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
	 */
	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
		// Depth-dependent classes.
		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
		$classes = array[
			'sub-menu',
			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
			'menu-depth-' . $display_depth
		];
		$class_names = implode[ ' ', $classes ];

		// Build HTML for output.
		$output .= "\n" . $indent . '
    ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
  • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
0 trên mục danh sách bên phải khi sử dụng trình tạo menu mặc định]

Tháng Tư 25, 2017 lúc 5. 57 giờ sáng

Beverleyh

người tham gia

@Atelierbram cảm ơn. . D

Đúng, cũng có nhiều cách để làm điều đó trong PHP. Đối với bất kỳ ai không sử dụng khung có thêm lớp, đây là một cách đơn giản để thực hiện điều đó trong PHP…

Ở đầu trang web – trên tất cả HTML, thậm chí cả doctype;


Điều này sẽ lấy giá trị “about-us” từ một URL giống như http. //www. trang web của tôi. com/about-us. php

Layload là một kỹ thuật JS để đảm bảo tải hình ảnh khi chúng xuất hiện trong chế độ xem để giảm thời gian tải trang của bạn. Trên hết, các ngón tay cái từ kirby có thể giúp bạn thay đổi kích thước hình ảnh của mình theo chiều rộng của chế độ xem

Nếu bạn đã thêm phần này vào tệp cấu hình của mình chẳng hạn

'thumbs' => [
    'srcsets' => [
       'teaser' => [
       '800w' => ['width' => 800, 'quality' => 100],
    '1024w' => ['width' => 1024, 'quality' => 100],
    '1440w' => ['width' => 1440, 'quality' => 100],
    '2048w' => ['width' => 2048, 'quality' => 100]
      ]
    ]
  ]

Sau đó, bạn có thể đặt các loại dòng này cho tất cả các hình ảnh của mình

wp_nav_menu[ array[
	'menu'   => 'Something custom walker',
	'walker' => new WPDocs_Walker_Nav_Menu[]
] ];

/**
 * Custom walker class.
 */
class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {

	/**
	 * Starts the list before the elements are added.
	 *
	 * Adds classes to the unordered list sub-menus.
	 *
	 * @param string $output Passed by reference. Used to append additional content.
	 * @param int    $depth  Depth of menu item. Used for padding.
	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
	 */
	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
		// Depth-dependent classes.
		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
		$classes = array[
			'sub-menu',
			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
			'menu-depth-' . $display_depth
		];
		$class_names = implode[ ' ', $classes ];

		// Build HTML for output.
		$output .= "\n" . $indent . '
    ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
  • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
1

gọi Lazysizes chẳng hạn trong cuộc gọi JS của bạn

GitHub 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }3 chuỗi

Làm thế nào các mục danh sách nên được bọc. Sử dụng định dạng printf[] với các trình giữ chỗ được đánh số. Mặc định là một ul có id và lớp

  • wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    4 chuỗi

    Có duy trì khoảng trắng trong HTML của menu không.
    Chấp nhận

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    5 hoặc
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    6. Mặc định
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    5.

  • Mặc định.

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    8

    khoảng trống. chuỗi. false Vô hiệu nếu đối số

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    9 là đúng, xuất menu nếu
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    9 là sai.
    Sai nếu không có mục nào hoặc không tìm thấy menu nào.

    'thumbs' => [
        'srcsets' => [
           'teaser' => [
           '800w' => ['width' => 800, 'quality' => 100],
        '1024w' => ['width' => 1024, 'quality' => 100],
        '1440w' => ['width' => 1440, 'quality' => 100],
        '2048w' => ['width' => 2048, 'quality' => 100]
          ]
        ]
      ]
    
    0

    Đưa ra một tham số theme_location, hàm sẽ hiển thị menu được gán cho vị trí đó. Nếu không có vị trí nào như vậy tồn tại hoặc không có menu nào được gán cho vị trí đó, tham số fallback_cb sẽ xác định nội dung được hiển thị

    Nếu không được cung cấp tham số theme_location, hàm sẽ hiển thị

    • menu khớp với ID, slug hoặc tên do thông số menu cung cấp;
    • mặt khác, menu không trống đầu tiên;
    • mặt khác [hoặc nếu menu được cung cấp bởi menu trống], đầu ra của hàm được cung cấp bởi tham số fallback_cb [wp_page_menu[] , theo mặc định];
    • nếu không thì không có gì

    The following classes are applied to menu items, i.e. to the HTML

  • tags, generated by
    'thumbs' => [
        'srcsets' => [
           'teaser' => [
           '800w' => ['width' => 800, 'quality' => 100],
        '1024w' => ['width' => 1024, 'quality' => 100],
        '1440w' => ['width' => 1440, 'quality' => 100],
        '2048w' => ['width' => 2048, 'quality' => 100]
          ]
        ]
      ]
    
    11:

    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      12
      Lớp này được thêm vào mọi mục menu.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      13
      Lớp này được thêm vào mục menu có mục phụ.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      14
      Lớp này được thêm vào mọi mục menu, trong đó {object} là loại bài đăng hoặc phân loại.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      15
      Lớp này được thêm vào các mục menu tương ứng với một danh mục.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      16
      Lớp này được thêm vào các mục menu tương ứng với thẻ.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      17
      Lớp này được thêm vào các mục menu tương ứng với các trang tĩnh.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      18
      Lớp này được thêm vào các mục menu tương ứng với loại bài đăng tùy chỉnh hoặc phân loại tùy chỉnh.
    • 'thumbs' => [
          'srcsets' => [
             'teaser' => [
             '800w' => ['width' => 800, 'quality' => 100],
          '1024w' => ['width' => 1024, 'quality' => 100],
          '1440w' => ['width' => 1440, 'quality' => 100],
          '2048w' => ['width' => 2048, 'quality' => 100]
            ]
          ]
        ]
      
      19
      Lớp này được thêm vào mọi mục menu, trong đó {type} là “post_type” hoặc “taxonomy”.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      00
      Lớp này được thêm vào các mục menu tương ứng với các loại bài đăng. tôi. e. trang tĩnh hoặc loại bài đăng tùy chỉnh.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      01
      Lớp này được thêm vào các mục menu tương ứng với các nguyên tắc phân loại. tôi. e. danh mục, thẻ hoặc phân loại tùy chỉnh.

    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      02
      Lớp này được thêm vào các mục menu tương ứng với trang hiện được hiển thị.

    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      03
      Lớp này được thêm vào các mục menu tương ứng với cấp bậc gốc của trang hiện được hiển thị.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      04
      Lớp này được thêm vào các mục menu tương ứng với cấp bậc gốc của đối tượng hiện được hiển thị, trong đó {object} tương ứng với giá trị được sử dụng cho. menu-item-object-{object}.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      05
      Lớp này được thêm vào các mục menu tương ứng với cấp bậc gốc của loại hiện được hiển thị, trong đó {type} tương ứng với giá trị được sử dụng cho. menu-item-type-{type}.

    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      06
      Lớp này được thêm vào các mục menu tương ứng với tổ tiên phân cấp của trang hiện được hiển thị.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      07
      Lớp này được thêm vào các mục menu tương ứng với tổ tiên phân cấp của đối tượng hiện được hiển thị, trong đó {đối tượng} tương ứng với giá trị được sử dụng cho. menu-item-object-{object}.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      08
      Lớp này được thêm vào các mục menu tương ứng với tổ tiên phân cấp của loại hiện được hiển thị, trong đó {type} tương ứng với giá trị được sử dụng cho. menu-item-type-{type}.

    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      09
      Lớp này được thêm vào các mục menu tương ứng với trang đầu của trang web.

    wp_page_menu[]

    Các lớp sau đây được thêm vào để duy trì khả năng tương thích ngược với [[Tham chiếu hàm/wp_page_menu. đầu ra hàm wp_page_menu[] ]]

    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      00
      Lớp này được thêm vào các mục menu tương ứng với trang tĩnh.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      01
      Lớp này được thêm vào các mục menu có các trang phụ trong đó.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      02
      Lớp này được thêm vào các mục menu tương ứng với trang tĩnh, trong đó $ID là ID trang tĩnh.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      03
      Lớp này được thêm vào các mục menu tương ứng với trang tĩnh hiện được hiển thị.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      04
      Lớp này được thêm vào các mục menu tương ứng với cấp bậc gốc của trang tĩnh hiện được hiển thị.
    • wp_nav_menu[ array[
      	'menu'   => 'Something custom walker',
      	'walker' => new WPDocs_Walker_Nav_Menu[]
      ] ];
      
      /**
       * Custom walker class.
       */
      class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
      
      	/**
      	 * Starts the list before the elements are added.
      	 *
      	 * Adds classes to the unordered list sub-menus.
      	 *
      	 * @param string $output Passed by reference. Used to append additional content.
      	 * @param int    $depth  Depth of menu item. Used for padding.
      	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
      	 */
      	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
      		// Depth-dependent classes.
      		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
      		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
      		$classes = array[
      			'sub-menu',
      			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
      			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
      			'menu-depth-' . $display_depth
      		];
      		$class_names = implode[ ' ', $classes ];
      
      		// Build HTML for output.
      		$output .= "\n" . $indent . '
        ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
      • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
      05
      Lớp này được thêm vào các mục menu tương ứng với tổ tiên phân cấp của trang tĩnh hiện được hiển thị.
  • Tập tin.

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    06. Xem tất cả tài liệu tham khảo

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    7

    0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }82. 4. 7. 0 Đã thêm đối số
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    4.
    3. 0. 0Giới thiệu.

    1. 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }0

      • 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }1

        Đăng nhập để thêm phản hồi
  • 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }09

    Ví dụ này sẽ loại bỏ danh sách không có thứ tự bao quanh các mục danh sách. Việc thay thế HTML bọc bằng trình xác định

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    30 dẫn đến việc chỉ xuất nội dung danh sách HTML cho các mục menu, vì
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    3 được tạo bằng cách sử dụng
    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    32

    wp_nav_menu[ array[
    	'menu'   => 'Something custom walker',
    	'walker' => new WPDocs_Walker_Nav_Menu[]
    ] ];
    
    /**
     * Custom walker class.
     */
    class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu {
    
    	/**
    	 * Starts the list before the elements are added.
    	 *
    	 * Adds classes to the unordered list sub-menus.
    	 *
    	 * @param string $output Passed by reference. Used to append additional content.
    	 * @param int    $depth  Depth of menu item. Used for padding.
    	 * @param array  $args   An array of arguments. @see wp_nav_menu[]
    	 */
    	function start_lvl[ &$output, $depth = 0, $args = array[] ] {
    		// Depth-dependent classes.
    		$indent = [ $depth > 0  ? str_repeat[ "\t", $depth ] : '' ]; // code indent
    		$display_depth = [ $depth + 1]; // because it counts the first submenu as 0
    		$classes = array[
    			'sub-menu',
    			[ $display_depth % 2  ? 'menu-odd' : 'menu-even' ],
    			[ $display_depth >=2 ? 'sub-sub-menu' : '' ],
    			'menu-depth-' . $display_depth
    		];
    		$class_names = implode[ ' ', $classes ];
    
    		// Build HTML for output.
    		$output .= "\n" . $indent . '
      ' . "\n"; } /** * Start the element output. * * Adds main/sub-classes to the list items and links. * * @param string $output Passed by reference. Used to append additional content. * @param object $item Menu item data object. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] * @param int $id Current item ID. */ function start_el[ &$output, $item, $depth = 0, $args = array[], $id = 0 ] { global $wp_query; $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent // Depth-dependent classes. $depth_classes = array[ [ $depth == 0 ? 'main-menu-item' : 'sub-menu-item' ], [ $depth >=2 ? 'sub-sub-menu-item' : '' ], [ $depth % 2 ? 'menu-item-odd' : 'menu-item-even' ], 'menu-item-depth-' . $depth ]; $depth_class_names = esc_attr[ implode[ ' ', $depth_classes ] ]; // Passed classes. $classes = empty[ $item->classes ] ? array[] : [array] $item->classes; $class_names = esc_attr[ implode[ ' ', apply_filters[ 'nav_menu_css_class', array_filter[ $classes ], $item ] ] ]; // Build HTML. $output .= $indent . '
    • '; // Link attributes. $attributes = ! empty[ $item->attr_title ] ? ' title="' . esc_attr[ $item->attr_title ] .'"' : ''; $attributes .= ! empty[ $item->target ] ? ' target="' . esc_attr[ $item->target ] .'"' : ''; $attributes .= ! empty[ $item->xfn ] ? ' rel="' . esc_attr[ $item->xfn ] .'"' : ''; $attributes .= ! empty[ $item->url ] ? ' href="' . esc_attr[ $item->url ] .'"' : ''; $attributes .= ' class="menu-link ' . [ $depth > 0 ? 'sub-menu-link' : 'main-menu-link' ] . '"'; // Build HTML output and pass through the proper filter. $item_output = sprintf[ '%1$s%3$s%4$s%5$s%6$s', $args->before, $attributes, $args->link_before, apply_filters[ 'the_title', $item->title, $item->ID ], $args->link_after, $args->after ]; $output .= apply_filters[ 'walker_nav_menu_start_el', $item_output, $item, $depth, $args ]; } }
    3 mặc định trước.
    [html]
    'Something custom walker', 'walker' => new WPDocs_Walker_Nav_Menu[] ] ]; /** * Custom walker class. */ class WPDocs_Walker_Nav_Menu extends Walker_Nav_Menu { /** * Starts the list before the elements are added. * * Adds classes to the unordered list sub-menus. * * @param string $output Passed by reference. Used to append additional content. * @param int $depth Depth of menu item. Used for padding. * @param array $args An array of arguments. @see wp_nav_menu[] */ function start_lvl[ &$output, $depth = 0, $args = array[] ] { // Depth-dependent classes. $indent = [ $depth > 0 ? str_repeat[ "\t", $depth ] : '' ]; // code indent $display_depth = [ $depth + 1]; // because it counts the first submenu as 0 $classes = array[ 'sub-menu', [ $display_depth % 2 ? 'menu-odd' : 'menu-even' ], [ $display_depth >=2 ? 'sub-sub-menu' : '' ], 'menu-depth-' . $display_depth ]; $class_names = implode[ ' ', $classes ]; // Build HTML for output. $output .= "\n" . $indent . '