我将一些自定义字段添加到附件中,大致在插件中这样做(基于this tutorial):
function myplugin_add_attachment_fields( $form_fields, $post ) {
$fields = array(
\'myplugin_credit\' => array(
\'label\' => \'Credit\',
\'input\' => \'text\',
\'application\' => \'image\',
\'exclusions\' => array(\'audio\', \'video\'),
\'helps\' => "e.g. \'Bob Ferris\'"
)
// More fields here.
);
foreach($fields as $name => $field_data) {
if ( preg_match( "/" . $field_data[\'application\'] . "/", $post->post_mime_type) && ! in_array( $post->post_mime_type, $field_data[\'exclusions\'] ) ) {
$field_data[\'value\'] = get_post_meta( $post->ID, \'_\' . $name, true );
$form_fields[$name] = $field_data;
}
}
return $form_fields;
}
add_filter( \'attachment_fields_to_edit\', \'myplugin_add_attachment_fields\', 11, 2 );
这一切都很好,但编辑媒体项目时字段如下所示:两个问题:如何使标签(“信用”、“出版商”)与输入字段本身垂直对齐?
如何使输入字段与页面上的标准字段一样宽?
我确实知道如何使用CSS来实现这一点,但我不知道如何在插件中以良好的WordPress方式实现这一点。
UPDATE: 如果它对任何人都有帮助,在使用socki03的答案添加了我自己的CSS文件后,我在其中添加了以下内容来解决布局问题:
.compat-attachment-fields th.label {
vertical-align: top;
}
.compat-attachment-fields,
.compat-attachment-fields input.text {
width: 100%;
}
.compat-attachment-fields p.help {
margin-top: 0.2em;
margin-left: 5px;
}