返回介绍

get_taxonomy_labels()

发布于 2017-09-11 00:19:01 字数 6478 浏览 936 评论 0 收藏 0

get_taxonomy_labels( WP_Taxonomy $tax )

Builds an object with all taxonomy labels out of a taxonomy object


description

Accepted keys of the label array in the taxonomy object:

  • name – general name for the taxonomy, usually plural. The same as and overridden by $tax->label. Default is Tags/Categories
  • singular_name – name for one object of this taxonomy. Default is Tag/Category
  • search_items – Default is Search Tags/Search Categories
  • popular_items – This string isn’t used on hierarchical taxonomies. Default is Popular Tags
  • all_items – Default is All Tags/All Categories
  • parent_item – This string isn’t used on non-hierarchical taxonomies. In hierarchical ones the default is Parent Category
  • parent_item_colon – The same as parent_item, but with colon : in the end
  • edit_item – Default is Edit Tag/Edit Category
  • view_item – Default is View Tag/View Category
  • update_item – Default is Update Tag/Update Category
  • add_new_item – Default is Add New Tag/Add New Category
  • new_item_name – Default is New Tag Name/New Category Name
  • separate_items_with_commas – This string isn’t used on hierarchical taxonomies. Default is "Separate tags with commas", used in the meta box.
  • add_or_remove_items – This string isn’t used on hierarchical taxonomies. Default is "Add or remove tags", used in the meta box when JavaScript is disabled.
  • choose_from_most_used – This string isn’t used on hierarchical taxonomies. Default is "Choose from the most used tags", used in the meta box.
  • not_found – Default is "No tags found"/"No categories found", used in the meta box and taxonomy list table.
  • no_terms – Default is "No tags"/"No categories", used in the posts and media list tables.
  • items_list_navigation – String for the table pagination hidden heading.
  • items_list – String for the table hidden heading.

Above, the first default value is for non-hierarchical taxonomies (like tags) and the second one is for hierarchical taxonomies (like categories).


参数

$tax

(WP_Taxonomy) (Required) Taxonomy object.


返回值

(object) object with all the labels as member variables.


源代码

File: wp-includes/taxonomy.php

function get_taxonomy_labels( $tax ) {
	$tax->labels = (array) $tax->labels;

	if ( isset( $tax->helps ) && empty( $tax->labels['separate_items_with_commas'] ) )
		$tax->labels['separate_items_with_commas'] = $tax->helps;

	if ( isset( $tax->no_tagcloud ) && empty( $tax->labels['not_found'] ) )
		$tax->labels['not_found'] = $tax->no_tagcloud;

	$nohier_vs_hier_defaults = array(
		'name' => array( _x( 'Tags', 'taxonomy general name' ), _x( 'Categories', 'taxonomy general name' ) ),
		'singular_name' => array( _x( 'Tag', 'taxonomy singular name' ), _x( 'Category', 'taxonomy singular name' ) ),
		'search_items' => array( __( 'Search Tags' ), __( 'Search Categories' ) ),
		'popular_items' => array( __( 'Popular Tags' ), null ),
		'all_items' => array( __( 'All Tags' ), __( 'All Categories' ) ),
		'parent_item' => array( null, __( 'Parent Category' ) ),
		'parent_item_colon' => array( null, __( 'Parent Category:' ) ),
		'edit_item' => array( __( 'Edit Tag' ), __( 'Edit Category' ) ),
		'view_item' => array( __( 'View Tag' ), __( 'View Category' ) ),
		'update_item' => array( __( 'Update Tag' ), __( 'Update Category' ) ),
		'add_new_item' => array( __( 'Add New Tag' ), __( 'Add New Category' ) ),
		'new_item_name' => array( __( 'New Tag Name' ), __( 'New Category Name' ) ),
		'separate_items_with_commas' => array( __( 'Separate tags with commas' ), null ),
		'add_or_remove_items' => array( __( 'Add or remove tags' ), null ),
		'choose_from_most_used' => array( __( 'Choose from the most used tags' ), null ),
		'not_found' => array( __( 'No tags found.' ), __( 'No categories found.' ) ),
		'no_terms' => array( __( 'No tags' ), __( 'No categories' ) ),
		'items_list_navigation' => array( __( 'Tags list navigation' ), __( 'Categories list navigation' ) ),
		'items_list' => array( __( 'Tags list' ), __( 'Categories list' ) ),
	);
	$nohier_vs_hier_defaults['menu_name'] = $nohier_vs_hier_defaults['name'];

	$labels = _get_custom_object_labels( $tax, $nohier_vs_hier_defaults );

	$taxonomy = $tax->name;

	$default_labels = clone $labels;

	/**
	 * Filters the labels of a specific taxonomy.
	 *
	 * The dynamic portion of the hook name, `$taxonomy`, refers to the taxonomy slug.
	 *
	 * @since 4.4.0
	 *
	 * @see get_taxonomy_labels() for the full list of taxonomy labels.
	 *
	 * @param object $labels Object with labels for the taxonomy as member variables.
	 */
	$labels = apply_filters( "taxonomy_labels_{$taxonomy}", $labels );

	// Ensure that the filtered labels contain all required default values.
	$labels = (object) array_merge( (array) $default_labels, (array) $labels );

	return $labels;
}

更新日志

Versiondescription
4.4.0Added the items_list_navigation and items_list labels.
4.3.0Added the no_terms label.
3.0.0Introduced.

相关函数

Uses

  • wp-includes/taxonomy.php: taxonomy_labels_{$taxonomy}
  • wp-includes/l10n.php: _x()
  • wp-includes/l10n.php: __()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: _get_custom_object_labels()

Used By

  • wp-includes/class-wp-taxonomy.php: WP_Taxonomy::set_props()

User Contributed Notes

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文