调用最近登录时间,最近文章更新时间(某指定会员)

较多的用在三栏布局主题中,例如在侧栏显示博主最近一篇文章是啥时候发表的,以及博主最近在线时间。

废话少说,直接上代码:

//调用博主最近登录时间
function get_last_login($user){
    $user   = '1';
    $now = time();
    $db     = Typecho_Db::get();
    $prefix = $db->getPrefix();
    $row = $db->fetchRow($db->select('activated')->from('table.users')->where('uid = ?', $user));
    echo Typecho_I18n::dateWord($row['activated'], $now);
}

调用语句示例:博主 <?php get_last_login(1); ?> 在线 

//调用博主最近文章更新时间
function get_last_update(){
    $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);
    }
}

调用语句示例:最新文章发表于 <?php get_last_update(); ?>

上述主代码放入 function.php 文件中,调用示例代码自行添加到需要显示的位置

文章由官网发布,如若转载,请注明出处:https://www.veimoz.com/296
0 评论
2.5k

发表评论

!