Adding a custom field to conditionally display last modified date:
您可以使用帖子的内置自定义字段元框。通常它在默认情况下是隐藏的,因此您必须在“屏幕选项”中启用它,并选中“自定义字段”框,如下所示:
如果使用新的块编辑器,可以通过转到
Edit Post Screen >
Click the three dots button on the top right corner >
Settings >
Advanced Panels.
现在,添加一个新的自定义字段,我们将其称为show_last_modified
并将其设置为true。
Displaying the last modified date:
功能
the_modified_date()
将为您提供上次修改帖子的日期。
要显示它,似乎必须覆盖mh_magazine_post_meta()
作用
function mh_magazine_post_meta() {
$mh_magazine_options = mh_magazine_theme_options();
if ($mh_magazine_options[\'post_meta_date\'] === \'enable\' || $mh_magazine_options[\'post_meta_author\'] === \'enable\' && in_the_loop() || $mh_magazine_options[\'post_meta_cat\'] === \'enable\' && in_the_loop() && is_singular() || $mh_magazine_options[\'post_meta_comments\'] === \'enable\') {
echo \'<div class="mh-meta entry-meta">\' . "\\n";
if ($mh_magazine_options[\'post_meta_date\'] === \'enable\') {
echo \'<span class="entry-meta-date updated"><i class="fa fa-clock-o"></i><a href="\' . esc_url(get_month_link(get_the_time(\'Y\'), get_the_time(\'m\'))) . \'">\' . get_the_date() . \'</a></span>\' . "\\n";
// Custom code
if(!empty(get_post_meta(get_the_ID(), \'show_last_modified\', true)){
echo \'Last modified date:\' . the_modified_date();
}
//
}
if ($mh_magazine_options[\'post_meta_author\'] === \'enable\' && in_the_loop()) {
echo \'<span class="entry-meta-author author vcard"><i class="fa fa-user"></i><a class="fn" href="\' . esc_url(get_author_posts_url(get_the_author_meta(\'ID\'))) . \'">\' . esc_html(get_the_author()) . \'</a></span>\' . "\\n";
}
if ($mh_magazine_options[\'post_meta_cat\'] === \'enable\' && in_the_loop() && is_singular()) {
echo \'<span class="entry-meta-categories"><i class="fa fa-folder-open-o"></i>\' . get_the_category_list(\', \', \'\') . \'</span>\' . "\\n";
}
if ($mh_magazine_options[\'post_meta_comments\'] === \'enable\') {
echo \'<span class="entry-meta-comments"><i class="fa fa-comment-o"></i>\';
mh_magazine_comment_count();
echo \'</span>\' . "\\n";
}
echo \'</div>\' . "\\n";
}
}
add_action(\'mh_post_header\', \'mh_magazine_post_meta\');
将上述代码放在子主题上,并自定义标记以满足您的需要。