我们看到有些WordPress网站内容页是有可以看到文章的发布和更新日期的。我们从SEO角度,时间戳对于内容的加权是有一些因素的,这里如果我们的网站没有更新时间戳可以手工加上。
<?php
$post_time = get_the_time('Y-m-d');
$update_time = get_the_modified_time('Y-m-d');
function dateBDate($date1, $date2) {
$date1_s = strtotime($date1);
$date2_s = strtotime($date2);
if ($date2_s - $date1_s > 0) {
return true;
} else {
return false;
}
}
if (!dateBDate($post_time, $update_time)) {
?>
<span class="item">发布于 <?php echo $post_time ?></span>
<?php
} else {
?>
<span class="item">发布于 <?php echo $post_time ?></span>
<span class="item">更新于 <?php echo $update_time ?></span>
<?php
}
?>
这里用到post_time和update_time即可,用到了get_the_time和get_the_modified_time这两个函数。我们可以根据需要添加到对应的single.php页面模板中。
1.3/5 – (3 votes)
© 版权声明
温馨提示:本站知识付费,提供的一切软件、教程和内容信息都来自网络收集整理,仅限用于学习和研究目的;不得将上述内容用于商业或者非法用途,否则,一切后果请用户自负,版权争议与本站无关。用户必须在下载后的24个小时之内,从您的电脑或手机中彻底删除上述内容。如果您喜欢该程序和内容,请支持正版,购买注册,得到更好的正版服务。我们非常重视版权问题,如有侵权请邮件与我们联系处理。敬请谅解!
THE END
暂无评论内容