函数部分
添加到主题目录下/function.php文件中即可。
function _getHistoryToday1($created)
{
$date = date('m/d', $created);
$time = time();
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
$sql = "SELECT * FROM `{$prefix}contents` WHERE DATE_FORMAT(FROM_UNIXTIME(created), '%m/%d') = '{$date}' and created <= {$time} and created != {$created} and type = 'post' and status = 'publish' and (password is NULL or password = '') LIMIT 5";
$result = $db->query($sql);
if ($result instanceof Traversable) {
foreach ($result as $item) {
$item = Typecho_Widget::widget('Widget_Abstract_Contents')->push($item);
$title = htmlspecialchars($item['title']);
$permalink = $item['permalink'];
echo "
<li class='item'>
<strong>{$date}</strong><a class='link' href='{$permalink}' title='{$title}'>{$title}</a>
</li>
";
}
}
}
文章内容页代码:
<div class="history">
<div class="title">那一年 · <span class="title-date"><?php $this->date('Y年 '); ?></span></div>
<?php _getHistoryToday1($this->created) ?>
</div>
代码添加到恰当位置再修改样式即可。
.history {
margin: 15px 0;
padding: 15px;
position: relative;
border: 1px dashed #dcdfe6;
line-height: 26px;
}
.history .title-date {
color: #409eff;
}
.history .title {
position: absolute;
top: 0;
left: 15px;
font-size: 15px;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
background: #fff;
padding: 0 5px;
color: #303133;
font-weight: 600;
}
.history .item {
display: flex;
align-items: center;
line-height: 30px;
}
.history .item strong {
color: #606266;
margin-right: 20px;
}
.history .item .link {
position: relative;
color: #606266;
max-width: 85%;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}