我的要求是为图像提供一个单独的版权字段,并显示每个图像的版权信息。为此,我基于此源在媒体库中插入了一个单独的字段(https://bavotasan.com/2012/add-a-copyright-field-to-the-media-uploader-in-wordpress/)遗憾的是,此片段仅适用于特色图像。
如何将此片段用于文章中的图像和库?这对代码库有用吗?如果没有,如果没有插件,您将如何解决这个问题?我将非常感谢你的帮助。
我的要求是为图像提供一个单独的版权字段,并显示每个图像的版权信息。为此,我基于此源在媒体库中插入了一个单独的字段(https://bavotasan.com/2012/add-a-copyright-field-to-the-media-uploader-in-wordpress/)遗憾的是,此片段仅适用于特色图像。
如何将此片段用于文章中的图像和库?这对代码库有用吗?如果没有,如果没有插件,您将如何解决这个问题?我将非常感谢你的帮助。
尝试以下操作:
/**
* Adding a "Copyright" field to the media uploader $form_fields array
*
* @param array $form_fields
* @param object $post
*
* @return array
*/
function add_copyright_field_to_media_uploader( $form_fields, $post ) {
$form_fields[\'copyright_field\'] = array(
\'label\' => __(\'Copyright\'),
\'value\' => get_post_meta( $post->ID, \'_custom_copyright\', true ),
\'helps\' => \'Set a copyright credit for the attachment\'
);
return $form_fields;
}
add_filter( \'attachment_fields_to_edit\', \'add_copyright_field_to_media_uploader\', null, 2 );
/**
* Save our new "Copyright" field
*
* @param object $post
* @param object $attachment
*
* @return array
*/
function add_copyright_field_to_media_uploader_save( $post, $attachment ) {
if ( ! empty( $attachment[\'copyright_field\'] ) )
update_post_meta( $post[\'ID\'], \'_custom_copyright\', $attachment[\'copyright_field\'] );
else
delete_post_meta( $post[\'ID\'], \'_custom_copyright\' );
return $post;
}
add_filter( \'attachment_fields_to_save\', \'add_copyright_field_to_media_uploader_save\', null, 2 );
/**
* Display our new "Copyright" field
*
* @param int $attachment_id
*
* @return array
*/
function get_featured_image_copyright( $atts ) {
extract(shortcode_atts(array(
\'id\' => \'\',
), $atts));
$attachment_id = ( empty( $id ) ) ? get_post_thumbnail_id() : (int) $id;
if ( $attachment_id ){
$output = "<div class=\'img-wrapper\'>";
$output .= "<img src=\'".wp_get_attachment_url($attachment_id)."\'>";
$output .= "<span>".get_post_meta( $attachment_id, \'_custom_copyright\', true )."</span>";
$output .= "</div>";
return $output;
}
}
add_shortcode( \'show_img_with_copyright\', \'get_featured_image_copyright\' );
然后在文章中的任何地方使用带有附件id的快捷码,如下所示:[show_img_with_copyright id=63]
测试和工作我有一个私有插件,可以导出所有没有“主题化”的帖子,所以输出的只是内容的html(帖子主题为H1,日期/时间为H2)。如果帖子包含表情符号,它会正确显示在主题页面上。但是如果我将HTML输出保存到一个文件中,表情符号会显示为🙁 这些是UniCode字符(我想),我需要生成的HTML页面将表情符号显示为图形图像。创建HTML输出的代码使用标准WP\\u查询对象,然后在have\\u posts循环中输出内容:$thest