我们看到有些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页面模板中。

声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。