函数
render_block_core_navigation_link ( $attributes, $content, $block )
- 参数
-
-
(array)
$attributes
The block attributes.- Required: 是
-
(string)
$content
The saved content.- Required: 是
-
(WP_Block)
$block
The parsed block.- Required: 是
-
(array)
- 返回值
-
- (string) Returns the post content with the legacy widget added.
- 定义位置
-
-
wp-includes/blocks/navigation-link.php
, line 132
-
wp-includes/blocks/navigation-link.php
- 引入
- –
- 弃用
- –
Renders the `core/navigation-link` block.
function render_block_core_navigation_link( $attributes, $content, $block ) {
$navigation_link_has_id = isset( $attributes['id'] ) && is_numeric( $attributes['id'] );
$is_post_type = isset( $attributes['kind'] ) && 'post-type' === $attributes['kind'];
$is_post_type = $is_post_type || isset( $attributes['type'] ) && ( 'post' === $attributes['type'] || 'page' === $attributes['type'] );
// Don't render the block's subtree if it is a draft or if the ID does not exist.
if ( $is_post_type && $navigation_link_has_id ) {
$post = get_post( $attributes['id'] );
if ( ! $post || 'publish' !== $post->post_status ) {
return '';
}
}
// Don't render the block's subtree if it has no label.
if ( empty( $attributes['label'] ) ) {
return '';
}
$colors = block_core_navigation_link_build_css_colors( $block->context, $attributes );
$font_sizes = block_core_navigation_link_build_css_font_sizes( $block->context );
$classes = array_merge(
$colors['css_classes'],
$font_sizes['css_classes']
);
$style_attribute = ( $colors['inline_styles'] . $font_sizes['inline_styles'] );
$css_classes = trim( implode( ' ', $classes ) );
$has_submenu = count( $block->inner_blocks ) > 0;
$is_active = ! empty( $attributes['id'] ) && ( get_queried_object_id() === (int) $attributes['id'] );
$wrapper_attributes = get_block_wrapper_attributes(
array(
'class' => $css_classes . ' wp-block-navigation-item' . ( $has_submenu ? ' has-child' : '' ) .
( $is_active ? ' current-menu-item' : '' ),
'style' => $style_attribute,
)
);
$html = '
”;
if ( isset( $attributes[‘label’] ) ) {
$html .= wp_kses_post( $attributes[‘label’] );
}
$html .= ”;
// Add description if available.
if ( ! empty( $attributes[‘description’] ) ) {
$html .= ‘‘;
}
$html .= ”;
// End anchor tag content.
if ( isset( $block->context[‘showSubmenuIcon’] ) && $block->context[‘showSubmenuIcon’] && $has_submenu ) {
// The submenu icon can be hidden by a CSS rule on the Navigation Block.
$html .= ‘‘;
}
if ( $has_submenu ) {
$inner_blocks_html = ”;
foreach ( $block->inner_blocks as $inner_block ) {
$inner_blocks_html .= $inner_block->render();
}
$html .= sprintf(
‘
‘,
$inner_blocks_html
);
}
$html .= ‘
‘;
return $html;
}


