wpseek.com
A WordPress-centric search engine for devs and theme authors



block_core_page_list_render_nested_page_list › WordPress Function

Sincen/a
Deprecatedn/a
block_core_page_list_render_nested_page_list ( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 )
Parameters: (8)
  • (bool) $open_submenus_on_click Whether to open submenus on click instead of hover.
    Required: Yes
  • (bool) $show_submenu_icons Whether to show submenu indicator icons.
    Required: Yes
  • (bool) $is_navigation_child If block is a child of Navigation block.
    Required: Yes
  • (array) $nested_pages The array of nested pages.
    Required: Yes
  • (bool) $is_nested Whether the submenu is nested or not.
    Required: Yes
  • (array) $active_page_ancestor_ids An array of ancestor ids for active page.
    Required: No
    Default: array()
  • (array) $colors Color information for overlay styles.
    Required: No
    Default: array()
  • (int) $depth The nesting depth.
    Required: No
    Default:
Returns:
  • (string) List markup.
Defined at:
Codex:

Outputs Page list markup from an array of pages with nested children.



Source

function block_core_page_list_render_nested_page_list( $open_submenus_on_click, $show_submenu_icons, $is_navigation_child, $nested_pages, $is_nested, $active_page_ancestor_ids = array(), $colors = array(), $depth = 0 ) {
	if ( empty( $nested_pages ) ) {
		return;
	}
	$front_page_id = (int) get_option( 'page_on_front' );
	$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 ( ( ( 0 < $depth && ! $is_nested ) || $is_nested ) && 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'] ) );
			}
		}

		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="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'], $is_nested, $active_page_ancestor_ids, $colors, $depth + 1 );
			$markup .= '</ul>';
		}
		$markup .= '</li>';
	}
	return $markup;
}