教程
Typecho获取站点最后活动时间
835

通过官网文档得知,Typecho文章的最后更新的时间可以通过代码获取

<?php echo date('Y 年 m 月 d 日', $this--->modified);?>

而我们是想获取站点最后更新时间即站点最后活动时间,目前我只在Typecho的一款主题handsome中看到有工具类实现,在我们自己的博客主题想要只能自己实现了,不过也不难。

function geLastUpdate(){
    $num   = '1';
    $now = time();
    $db     = Typecho_Db::get();
    $prefix = $db->getPrefix();
    $create = $db->fetchRow($db->select('created')->from('table.contents')->limit($num)->order('created',Typecho_Db::SORT_DESC));
    $update = $db->fetchRow($db->select('modified')->from('table.contents')->limit($num)->order('modified',Typecho_Db::SORT_DESC));
    if($create>=$update){  //发表时间和更新时间取最近的
      echo Typecho_I18n::dateWord($create['created'], $now); //转换为更通俗易懂的格式
    }else{
      echo Typecho_I18n::dateWord($update['modified'], $now);
    }
    }

函数放在我们主题下的 function.php 文件中,在我们需要的位置调用即可。

<?php getLastUpdate();?>

效果显示

结语

感谢访问强仔博客,希望本文对你有所帮助!


  • 上一篇
  • 下一篇
  • 添加评论
    welcome to qiangzai blog