block_core_page_list_render_nested_page_list

函数
block_core_page_list_render_nested_page_list ( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 )
参数
  • (bool) $open_submenus_on_click Whether to open submenus on click instead of hover.
    Required:
  • (bool) $show_submenu_icons Whether to show submenu indicator icons.
    Required:
  • (bool) $is_navigation_child If block is a child of Navigation block.
    Required:
  • (array) $nested_pages The array of nested pages.
    Required:
  • (array) $active_page_ancestor_ids An array of ancestor ids for active page.
    Required:
    Default: array()
  • (array) $colors Color information for overlay styles.
    Required:
    Default: array()
  • (int) $depth The nesting depth.
    Required:
返回值
  • (string) List markup.
定义位置
相关方法
block_core_page_list_nest_pagesblock_core_navigation_link_render_submenu_iconblock_core_post_template_uses_featured_imageblock_core_navigation_render_submenu_iconblock_core_calendar_has_published_posts
引入
-
弃用
-

block_core_page_list_render_nested_page_list: 这个函数用来渲染嵌套的页面列表块。它以分层的顺序显示嵌套的页面。

从一个带有嵌套子实体的页面数组中输出页面列表标记。

function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) {
	if ( empty( $nested_pages ) ) {
		return;
	}
	$markup = '';
	foreach ( (array) $nested_pages as $page ) {
		$css_class       = $page['is_active'] ? ' current-menu-item' : '';
		$aria_current    = $page['is_active'] ? ' aria-current="page"' : '';
		$style_attribute = '';

		$css_class .= in_array( $page['page_id'], $active_page_ancestor_ids, true ) ? ' current-menu-ancestor' : '';
		if ( isset( $page['children'] ) ) {
			$css_class .= ' has-child';
		}

		if ( $is_navigation_child ) {
			$css_class .= ' wp-block-navigation-item';

			if ( $open_submenus_on_click ) {
				$css_class .= ' open-on-click';
			} elseif ( $show_submenu_icons ) {
				$css_class .= ' open-on-hover-click';
			}
		}

		$navigation_child_content_class = $is_navigation_child ? ' wp-block-navigation-item__content' : '';

		// If this is the first level of submenus, include the overlay colors.
		if ( 1 === $depth && isset( $colors['overlay_css_classes'], $colors['overlay_inline_styles'] ) ) {
			$css_class .= ' ' . trim( implode( ' ', $colors['overlay_css_classes'] ) );
			if ( '' !== $colors['overlay_inline_styles'] ) {
				$style_attribute = sprintf( ' style="%s"', esc_attr( $colors['overlay_inline_styles'] ) );
			}
		}

		$front_page_id = (int) get_option( 'page_on_front' );
		if ( (int) $page['page_id'] === $front_page_id ) {
			$css_class .= ' menu-item-home';
		}

		$title      = wp_kses_post( $page['title'] );
		$aria_label = sprintf(
			/* translators: Accessibility text. %s: Parent page title. */
			__( '%s submenu' ),
			wp_strip_all_tags( $title )
		);

		$markup .= '<li class="wp-block-pages-list__item' . esc_attr( $css_class ) . '"' . $style_attribute . '>';

		if ( isset( $page['children'] ) && $is_navigation_child && $open_submenus_on_click ) {
			$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="' . esc_attr( $navigation_child_content_class ) . ' wp-block-navigation-submenu__toggle" aria-expanded="false">' . esc_html( $title ) .
			'</button>' . '<span class="wp-block-page-list__submenu-icon wp-block-navigation__submenu-icon"><svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg></span>';
		} else {
			$markup .= '<a class="wp-block-pages-list__item__link' . esc_attr( $navigation_child_content_class ) . '" href="' . esc_url( $page['link'] ) . '"' . $aria_current . '>' . $title . '</a>';
		}

		if ( isset( $page['children'] ) ) {
			if ( $is_navigation_child && $show_submenu_icons && ! $open_submenus_on_click ) {
				$markup .= '<button aria-label="' . esc_attr( $aria_label ) . '" class="wp-block-navigation__submenu-icon wp-block-navigation-submenu__toggle" aria-expanded="false">';
				$markup .= '<svg xmlns="http://www.w3.org/2000/svg" width="12" height="12" viewBox="0 0 12 12" fill="none" aria-hidden="true" focusable="false"><path d="M1.50002 4L6.00002 8L10.5 4" stroke-width="1.5"></path></svg>';
				$markup .= '</button>';
			}
			$markup .= '<ul class="submenu-container';
			// Extra classname is added when the block is a child of Navigation.
			if ( $is_navigation_child ) {
				$markup .= ' wp-block-navigation__submenu-container';
			}
			$markup .= '">' . block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $page['children'], $active_page_ancestor_ids, $colors, $depth + 1 ) . '</ul>';
		}
		$markup .= '</li>';
	}
	return $markup;
}

常见问题

FAQs
查看更多 >