問題描述
問題是 「如何在 WordPress 管理員的類別,標籤和自定義分類編輯屏幕中添加一個或多個字段?」 這個問題是 asked on the wp-hackers list 2010 年 8 月 1 日和 I offered a solution 當天晚些時候。 original asker discussed the issue again 今天 (8 月 21 日) 提醒我解決方案。既然可能是一個常見的需求,我決定把這個解決方案發布給他人,以備將來找到。
最佳解決方案
我在這些幫助下添加了新的字段’picture'(輸入類型文件) 到類別
add_action('category_edit_form_fields','category_edit_form_fields');
add_action('category_edit_form', 'category_edit_form');
add_action('category_add_form_fields','category_edit_form_fields');
add_action('category_add_form','category_edit_form');
function category_edit_form() {
?>
<script type="text/javascript">
jQuery(document).ready(function(){
jQuery('#edittag').attr( "enctype", "multipart/form-data" ).attr( "encoding", "multipart/form-data" );
});
</script>
<?php
}
function category_edit_form_fields () {
?>
<tr class="form-field">
<th valign="top" scope="row">
<label for="catpic"><?php _e('Picture of the category', ''); ?></label>
</th>
<td>
<input type="file" id="catpic" name="catpic"/>
</td>
</tr>
<?php
}
您可以自由使用任何分類,只需將 category 替換為您的分類名稱
次佳解決方案
此外,如果要將該字段添加到自定義分類表單中,您只需使用 add_action 函數中的自定義分類名稱替換類別。
例:
add_action('{custom_taxonomy}_edit_form_fields','category_edit_form_fields');
add_action('{custom_taxonomy}_edit_form', 'category_edit_form');
add_action('{custom_taxonomy}_add_form_fields','category_edit_form_fields');
add_action('{custom_taxonomy}_add_form','category_edit_form');
參考文獻
注:本文內容整合自 Google/Baidu/Bing 輔助翻譯的英文資料結果。如果您對結果不滿意,可以加入我們改善翻譯效果:薇曉朵技術論壇。