8

给TP-log博客系统添加“文章最后更新时间”功能

 4 years ago
source link: https://qq.md/posts/161
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

发布: 4天前 围观: 150 分类: 编程代码

给TP-log博客系统添加“文章最后更新时间”功能

因为这个主题有个最后更新于xxx时间,“TP-log”我印象中是有这个最后更新代码的,然后一顿寻找没有...

只有这个发布时间时间{$list[0]->datetime|smartDate},无奈那只有自己想办法添加一个了。

作为一个小白我可不懂这些代码,只能查看代码大概分析一下。

  • $list[0]-> 读取数据库
  • datetime 获取的数据库时间
  • smartDate 转换数据库时间格式

上面分析完以后,我打开了Navicat Premium 12 查看数据库文章字段,如下:

看到了datetime 那这个字段就是发布时间 继续看看其他的

datetime

在旁边果然我又看到一个字段updatetime如果没猜错的话,这个就是最后更新时间了。

updatetime

发现这个字段以后我试这改成{$list[0]->updatetime|smartDate}测试能否正输出最后更新时间!

结果提示:类的属性不存在:app\frontend\logic\Blog->updatetime

那就是说明没有从数据库读取这个字段,那我从源头入手$list[0]->查看这个读取数据库的代码,打开文件application\frontend\controller\Posts.php查看分析。

50feca0ca7a6dccc40f8dc3978c03a93.png

看到这里的时候我想起来上次凡哥的文章“Tp-log修改正文页面中的Title,Keywords,Description”里面就有类似的操作。

43行__BLOG__.datetime,后面添加代码__BLOG__.updatetime,这样就成功读取最后更新时间了,如下图:

1a63be6bf0250d84a9cd3ae85793691b.png

这时候我们在用代码{$list[0]->updatetime|smartDate}看看效果如何

d94d6263c926ef9252de15ad26a5b8f3.png

这次没有任何吧报错,也成功读取显示正常,但是我希望是2021-6-5 xxx 这样的时间格式,没办法只能在修改一下smartDate 转换数据库时间格式这个代码。

打开文件application\common.php 找到下图代码:

dedb346402fd7b1532389bf0e21cb76b.png

在其后面添加如下代码:

function upsmartDate($unixtime, $dstr = 'Y-m-d H:i') {
      return date('Y-m-d H:i:s', $unixtime);  
}

效果:最后更新于:2021-06-05 18:35:20 调用代码:{$list[0]->updatetime|upsmartDate}

{$list[0]->datetime|smartDate} 是发布时间,效果:发布: xxx天前

{$list[0]->updatetime|upsmartDate} 是最后更新时间,效果:2021-06-05 18:35:20

不得不说"凡哥"是给我把地图路线都标记好了,我就顺着他的地图标记前行或者参考就行,哈哈哈哈哈!!!

"凡哥"最近在写小说,如果写好了也请大家多多支持一下哈!!!

33bcf10096f5d75528dd16d05f741313.png

# TP-log

  • 最后更新于:2021-06-05 19:25:10

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK