register_taxonomy_for_object_type(\'post_tag\', \'attachment\');
应该做到这一点。我认为您甚至可以从主题功能中执行此操作。php。
编辑:好,试试这个(在插件文件夹中另存为attachmenttags/attachmenttags.php,确保WP可以读取它,然后在插件管理器中激活):
/*
Plugin Name: AttachmentTags
Description: enables tagging attachments
Author: Wyrfel <[email protected]>
Version: 0.1
*/
if (!class_exists(\'AttachmentTags\') {
class AttachmentTags {
function AttachmentTags() {
add_action(\'admin_init\', (&$this, \'admin_init\'));
add_filter(\'wp_get_attachment_image_attributes\', (&$this, \'add_tag_classes\'), 10, 2);
}
function admin_init() {
register_taxonomy_for_object_type(\'post_tag\', \'attachment\');
}
function add_tag_classes($attr, $attachment) {
$tags = wp_get_object_terms($attachment->ID, \'post_tag\', \'names\');
if (!empty($tags)) foreach ($tags as $tag) {
$attr[\'class\'] .= \' \'.$tag; //wp sanitizes afterwards, so we don\'t need to
}
return $attr;
}
}
$AttachmentTags = new AttachmentTags();
}
顺便说一句:在编辑实际帖子/页面时,这还会在添加/编辑图像弹出窗口中创建帖子标签字段
再次编辑后,无论何时在主题中使用get\\u the\\u post\\u thumbnail(),都应该插入类。