返回介绍

wp_popular_terms_checklist()

发布于 2017-09-11 12:34:58 字数 3802 浏览 1511 评论 0 收藏 0

wp_popular_terms_checklist( string $taxonomy,  int $default,  int $number = 10,  bool $echo = true )

Retrieve a list of the most popular terms from the specified taxonomy.


description

If the $echo argument is true then the elements for a list of checkbox <input> elements labelled with the names of the selected terms is output. If the $post_ID global isn’t empty then the terms associated with that post will be marked as checked.


参数

$taxonomy

(string) (Required) Taxonomy to retrieve terms from.

$default

(int) (Required) Not used.

$number

(int) (Optional) Number of terms to retrieve. Defaults to 10.

Default value: 10

$echo

(bool) (Optional) y output the list as well. Defaults to true.

Default value: true


返回值

(array) List of popular term IDs.


源代码

File: wp-admin/includes/template.php

function wp_popular_terms_checklist( $taxonomy, $default = 0, $number = 10, $echo = true ) {
	$post = get_post();

	if ( $post && $post->ID )
		$checked_terms = wp_get_object_terms($post->ID, $taxonomy, array('fields'=>'ids'));
	else
		$checked_terms = array();

	$terms = get_terms( $taxonomy, array( 'orderby' => 'count', 'order' => 'DESC', 'number' => $number, 'hierarchical' => false ) );

	$tax = get_taxonomy($taxonomy);

	$popular_ids = array();
	foreach ( (array) $terms as $term ) {
		$popular_ids[] = $term->term_id;
		if ( !$echo ) // Hack for Ajax use.
			continue;
		$id = "popular-$taxonomy-$term->term_id";
		$checked = in_array( $term->term_id, $checked_terms ) ? 'checked="checked"' : '';
		?>

		<li id="<?php echo $id; ?>" class="popular-category">
			<label class="selectit">
				<input id="in-<?php echo $id; ?>" type="checkbox" <?php echo $checked; ?> value="<?php echo (int) $term->term_id; ?>" <?php disabled( ! current_user_can( $tax->cap->assign_terms ) ); ?> />
				<?php
				/** This filter is documented in wp-includes/category-template.php */
				echo esc_html( apply_filters( 'the_category', $term->name ) );
				?>
			</label>
		</li>

		<?php
	}
	return $popular_ids;
}

更新日志

Versiondescription
2.5.0Introduced.

相关函数

Uses

  • wp-includes/capabilities.php: current_user_can()
  • wp-includes/category-template.php: the_category
  • wp-includes/formatting.php: esc_html()
  • wp-includes/general-template.php: disabled()
  • wp-includes/taxonomy.php: wp_get_object_terms()
  • wp-includes/taxonomy.php: get_terms()
  • wp-includes/taxonomy.php: get_taxonomy()
  • wp-includes/plugin.php: apply_filters()
  • wp-includes/post.php: get_post()
  • Show 4 more uses Hide more uses

Used By

  • wp-admin/includes/ajax-actions.php: _wp_ajax_add_hierarchical_term()
  • wp-admin/includes/meta-boxes.php: link_categories_meta_box()
  • wp-admin/includes/meta-boxes.php: post_categories_meta_box()

User Contributed Notes

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

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

发布评论

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