wp_link_category_checklist

函数
wp_link_category_checklist ( $link_id = 0 )
参数
  • (int) $link_id
    Required:
定义位置
相关方法
wp_category_checklistwp_terms_checklistwp_popular_terms_checklistwp_list_categoriesclean_category_cache
引入
2.5.1
弃用
-

wp_link_category_checklist: 这个函数输出一个链接类别的HTML检查表,可以用来把链接分配给一个类别。

输出一个链接类别检查表元素。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
function wp_link_category_checklist( $link_id = 0 ) {
$default = 1;
$checked_categories = array();
if ( $link_id ) {
$checked_categories = wp_get_link_cats( $link_id );
// No selected categories, strange.
if ( ! count( $checked_categories ) ) {
$checked_categories[] = $default;
}
} else {
$checked_categories[] = $default;
}
$categories = get_terms(
array(
'taxonomy' => 'link_category',
'orderby' => 'name',
'hide_empty' => 0,
)
);
if ( empty( $categories ) ) {
return;
}
foreach ( $categories as $category ) {
$cat_id = $category->term_id;
/** This filter is documented in wp-includes/category-template.php */
$name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
$checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : '';
echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>';
}
}
function wp_link_category_checklist( $link_id = 0 ) { $default = 1; $checked_categories = array(); if ( $link_id ) { $checked_categories = wp_get_link_cats( $link_id ); // No selected categories, strange. if ( ! count( $checked_categories ) ) { $checked_categories[] = $default; } } else { $checked_categories[] = $default; } $categories = get_terms( array( 'taxonomy' => 'link_category', 'orderby' => 'name', 'hide_empty' => 0, ) ); if ( empty( $categories ) ) { return; } foreach ( $categories as $category ) { $cat_id = $category->term_id; /** This filter is documented in wp-includes/category-template.php */ $name = esc_html( apply_filters( 'the_category', $category->name, '', '' ) ); $checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : ''; echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>'; } }
function wp_link_category_checklist( $link_id = 0 ) {
	$default = 1;

	$checked_categories = array();

	if ( $link_id ) {
		$checked_categories = wp_get_link_cats( $link_id );
		// No selected categories, strange.
		if ( ! count( $checked_categories ) ) {
			$checked_categories[] = $default;
		}
	} else {
		$checked_categories[] = $default;
	}

	$categories = get_terms(
		array(
			'taxonomy'   => 'link_category',
			'orderby'    => 'name',
			'hide_empty' => 0,
		)
	);

	if ( empty( $categories ) ) {
		return;
	}

	foreach ( $categories as $category ) {
		$cat_id = $category->term_id;

		/** This filter is documented in wp-includes/category-template.php */
		$name    = esc_html( apply_filters( 'the_category', $category->name, '', '' ) );
		$checked = in_array( $cat_id, $checked_categories, true ) ? ' checked="checked"' : '';
		echo '<li id="link-category-', $cat_id, '"><label for="in-link-category-', $cat_id, '" class="selectit"><input value="', $cat_id, '" type="checkbox" name="link_category[]" id="in-link-category-', $cat_id, '"', $checked, '/> ', $name, '</label></li>';
	}
}

常见问题

FAQs
查看更多 >