render_block_core_tag_cloud

函数
render_block_core_tag_cloud ( $attributes )
参数
  • (array) $attributes The block attributes.
    Required:
返回值
  • (string) Returns the tag cloud for selected taxonomy.
定义位置
相关方法
register_block_core_tag_cloudrender_block_core_site_logorender_block_core_page_listrender_block_core_imagerender_block_core_cover
引入
-
弃用
-

render_block_core_tag_cloud: 这是一个WordPress的核心函数,用于在编辑器中呈现标签云块。它用于在网站的前端输出该块的HTML标记。

在服务器上渲染`core/tag-cloud’区块。

function render_block_core_tag_cloud( $attributes ) {
	$smallest_font_size = $attributes['smallestFontSize'];
	$unit               = ( preg_match( '/^[0-9.]+(?P<unit>[a-z%]+)$/i', $smallest_font_size, $m ) ? $m['unit'] : 'pt' );

	$args      = array(
		'echo'       => false,
		'unit'       => $unit,
		'taxonomy'   => $attributes['taxonomy'],
		'show_count' => $attributes['showTagCounts'],
		'number'     => $attributes['numberOfTags'],
		'smallest'   => floatVal( $attributes['smallestFontSize'] ),
		'largest'    => floatVal( $attributes['largestFontSize'] ),
	);
	$tag_cloud = wp_tag_cloud( $args );

	if ( ! $tag_cloud ) {
		$labels    = get_taxonomy_labels( get_taxonomy( $attributes['taxonomy'] ) );
		$tag_cloud = esc_html(
			sprintf(
				/* translators: %s: taxonomy name */
				__( 'Your site doesn’t have any %s, so there’s nothing to display here at the moment.' ),
				strtolower( $labels->name )
			)
		);
	}

	$wrapper_attributes = get_block_wrapper_attributes();

	return sprintf(
		'<p %1$s>%2$s</p>',
		$wrapper_attributes,
		$tag_cloud
	);
}

常见问题

FAQs
查看更多 >