我经营着一个新闻网站,我认为在其中添加最后日期更新选项有很大的好处。然而,我在网上看到的一切都是为了用修改后的日期替换发布日期。我两者都想要,就像in this article by the NYT.
更重要的是,我不希望每篇文章都出现这种情况,因为我经常编辑文章,也不希望每篇文章都反映出这种情况。取而代之的是,我想让它成为“常青树”的内容,而这些内容在出版后很久就被证明很受欢迎;我希望谷歌能在搜索结果中显示最近的时间。因此,我更喜欢使用自定义字段或CF插件来实现这一点——我目前已经安装了CMB2。
我使用的不是很有用的主题使用以下函数向帖子添加日期:
if (!function_exists(\'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";
}
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\');
我该怎么做?我不喜欢安装插件,所以我正在考虑一些我可以自己添加并通过自定义字段调用的东西。