Browse Source

文章详情页添加修改时间

wqg 3 weeks ago
parent
commit
fb52f699e1
2 changed files with 15 additions and 1 deletions
  1. 4 1
      usr/themes/default/post.php
  2. 11 0
      var/Widget/Base/Contents.php

+ 4 - 1
usr/themes/default/post.php

@@ -13,9 +13,12 @@
                                        href="<?php $this->author->permalink(); ?>"
                                        rel="author"><?php $this->author(); ?></a>
             </li>
-            <li><?php _e('时间: '); ?>
+            <li><?php _e('发布时间: '); ?>
                 <time datetime="<?php $this->date('c'); ?>" itemprop="datePublished"><?php $this->date(); ?></time>
             </li>
+            <li><?php _e('更新时间: '); ?>
+                <time datetime="<?php $this->dateM('c'); ?>" itemprop="datePublished"><?php $this->dateM(); ?></time>
+            </li>
             <li><?php _e('分类: '); ?><?php $this->category(','); ?></li>
         </ul>
         <div class="post-content" itemprop="articleBody">

+ 11 - 0
var/Widget/Base/Contents.php

@@ -523,6 +523,7 @@ class Contents extends Base implements QueryInterface
         }
 
         $value['date'] = new Date($value['created']);
+        $value['dateM'] = new Date($value['modified']);
 
         /** 生成日期 */
         $value['year'] = $value['date']->year;
@@ -628,6 +629,16 @@ class Contents extends Base implements QueryInterface
     {
         echo $this->date->format(empty($format) ? $this->options->postDateFormat : $format);
     }
+    
+    /**
+     * 输出文章修改日期
+     *
+     * @param string|null $format 日期格式
+     */
+    public function dateM(?string $format = null)
+    {
+        echo $this->dateM->format(empty($format) ? $this->options->postDateFormat : $format);
+    }
 
     /**
      * 输出文章内容