block_core_post_template_uses_featured_image

函数
block_core_post_template_uses_featured_image ( $inner_blocks )
参数
  • (WP_Block_List) $inner_blocks Inner block instance.
    Required:
返回值
  • (bool) Whether the block list contains a block that uses the featured image.
定义位置
相关方法
render_block_core_post_featured_imageregister_block_core_post_featured_imagerender_block_core_post_templateget_block_core_post_featured_image_border_attributesblock_core_comment_template_render_comments
引入
-
弃用
-

block_core_post_template_uses_featured_image: 该函数用于检查文章模板是否使用了特色图片。如果文章模板使用了特色图片,则返回true,否则返回false。

决定一个区块列表是否包含使用特色图片的区块。

function block_core_post_template_uses_featured_image( $inner_blocks ) {
	foreach ( $inner_blocks as $block ) {
		if ( 'core/post-featured-image' === $block->name ) {
			return true;
		}
		if (
			'core/cover' === $block->name &&
			! empty( $block->attributes['useFeaturedImage'] )
		) {
			return true;
		}
		if ( $block->inner_blocks && block_core_post_template_uses_featured_image( $block->inner_blocks ) ) {
			return true;
		}
	}

	return false;
}

常见问题

FAQs
查看更多 >