自定义分类法很棒。我注册了一系列新的分类法,并编写了一个导入程序,将我们的层次分类法导入到WordPress的XML中。问题是,一个分类法有大约1100个术语,浏览1100件事情的清单是残酷而不寻常的惩罚。
除了使用标记界面(具有自动完成功能的搜索框)之外,是否有其他方法可以使用层次分类法?
Update: Bainternet答案中的这段代码大部分都是这样的(为指定的分类法添加了标记接口,具有可工作的自动完成和正确填充的“最常用”标记云),但术语不会在保存后保存。如果帖子之前有条款,保存时会删除。所以我仍然在寻找答案。(如果分类法注册在hierarchichal
设置为false,但问题的关键是在层次分类法上使用标记接口。)
//remove default metabox
//change TAXONOMY_NAME to your taxonomy name
add_action( \'admin_menu\' , \'remove_post_custom_fields\' );
function remove_post_custom_fields() {
remove_meta_box( \'issuediv\' , \'post\' , \'normal\' );
}
//add our custom meta box
add_action( \'add_meta_boxes\', \'my_add_custom_box\' );
function my_add_custom_box() {
add_meta_box(
// \'myplugin_sectionid\',
\'tagsdiv-issue\',
__( \'New and Improved Issue Tags\', \'textdomain\' ),
\'tags_like_custom_tax\',
\'post\'
);
}
//call back function to display the metabox
//change TAXONOMY_NAME to your taxonomy name
function tags_like_custom_tax(){
$tax_name = \'issue\';
global $post;
$taxonomy = get_taxonomy($tax_name);
$disabled = !current_user_can($taxonomy->cap->assign_terms) ? \'disabled="disabled"\' : \'\';
?>
<div class="tagsdiv" id="<?php echo $tax_name; ?>">
<div class="jaxtag">
<div class="nojs-tags hide-if-js">
<p><?php echo $taxonomy->labels->add_or_remove_items; ?></p>
<textarea name="<?php echo "tax_input[$tax_name]"; ?>" rows="3" cols="20" class="the-tags" id="tax-input-<?php echo $tax_name; ?>" <?php echo $disabled; ?>><?php echo get_terms_to_edit( $post->ID, $tax_name ); // textarea_escaped by esc_attr() ?></textarea>
</div>
<?php if ( current_user_can($taxonomy->cap->assign_terms) ) { ?>
<div class="ajaxtag hide-if-no-js">
<label class="screen-reader-text" for="new-tag-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->name; ?></label>
<div class="taghint"><?php echo $taxonomy->labels->add_new_item; ?></div>
<p><input type="text" id="new-tag-<?php echo $tax_name; ?>" name="newtag[<?php echo $tax_name; ?>]" class="newtag form-input-tip" size="16" autocomplete="off" value="" />
<input type="button" class="button tagadd" value="<?php esc_attr_e(\'Add\'); ?>" tabindex="3" /></p>
</div>
<p class="howto"><?php echo esc_attr( $taxonomy->labels->separate_items_with_commas ); ?></p>
<?php } ?>
</div>
<div class="tagchecklist"></div>
</div>
<?php if ( current_user_can($taxonomy->cap->assign_terms) ) { ?>
<p class="hide-if-no-js"><a href="#titlediv" class="tagcloud-link" id="link-<?php echo $tax_name; ?>"><?php echo $taxonomy->labels->choose_from_most_used; ?></a></p>
<?php }
}
原始问题来自Wordpress论坛帖子here.