在后期编辑屏幕中,您可以将数据添加为自定义字段,然后将这些自定义字段拉入您的后期模板,如下所示:
如果您想为这些字段提供更好的管理界面,这是可能的,而且在web和本网站上有很多指南。搜索
admin metabox
.
要将数据拉入主题,请将此未测试的代码添加到functions.php
或者,如果你无法编辑主题,请将其添加到你自己的插件中。
function wpse_235005_post_meta(){
if ( !is_single() ) {
return;
/* bail out if not showing a single post of the right type
You may want to adjust this conditional to suit your site,
maybe checking for a custom post type
*/
}
global $post; // outside the loop make sure we can see this post
$fields = array(
"citation_publication_date",
"citation_journal_title",
"citation_volume",
"citation_issue",
"citation_firstpage",
"citation_lastpage",
"citation_pdf_url"
)
foreach( $fields as $field ) {
if( $value = get_post_meta($post->ID, $field, true) ) {
// in PHP empty strings are falsy
echo \'<meta name="\';
echo $field;
echo \'" content="\';
echo $value;
echo \'">\';
}
}
}
add_action(\'wp_head\', \'wpse_235005_post_meta\');
/* adjust the priority to move your meta elements up or down
within your document\'s head
*/