build_variation_for_navigation_link

函数
build_variation_for_navigation_link ( $entity, $kind )
参数
  • (WP_Taxonomy|WP_Post_Type) $entity post type or taxonomy entity.
    Required:
  • (string) $kind string of value 'taxonomy' or 'post-type'.
    Required:
返回值
  • (array)
定义位置
相关方法
register_block_core_navigation_linkrender_block_core_navigation_linkregister_block_core_post_navigation_linkrender_block_core_post_navigation_linkblock_core_navigation_link_build_css_colors
引入
-
弃用
-

build_variation_for_navigation_link: 这个函数用来为一个导航链接建立一个变体。它接收一个参数,即变体的选项数组。它返回一个导航链接的变体数组。

返回一个导航链接的变体

function build_variation_for_navigation_link( $entity, $kind ) {
	$title       = '';
	$description = '';

	if ( property_exists( $entity->labels, 'item_link' ) ) {
		$title = $entity->labels->item_link;
	}
	if ( property_exists( $entity->labels, 'item_link_description' ) ) {
		$description = $entity->labels->item_link_description;
	}

	$variation = array(
		'name'        => $entity->name,
		'title'       => $title,
		'description' => $description,
		'attributes'  => array(
			'type' => $entity->name,
			'kind' => $kind,
		),
	);

	// Tweak some value for the variations.
	$variation_overrides = array(
		'post_tag'    => array(
			'name'       => 'tag',
			'attributes' => array(
				'type' => 'tag',
				'kind' => $kind,
			),
		),
		'post_format' => array(
			// The item_link and item_link_description for post formats is the
			// same as for tags, so need to be overridden.
			'title'       => __( 'Post Format Link' ),
			'description' => __( 'A link to a post format' ),
			'attributes'  => array(
				'type' => 'post_format',
				'kind' => $kind,
			),
		),
	);

	if ( array_key_exists( $entity->name, $variation_overrides ) ) {
		$variation = array_merge(
			$variation,
			$variation_overrides[ $entity->name ]
		);
	}

	return $variation;
}

常见问题

FAQs
查看更多 >