typecho 获取文章最新样式,可直接放到侧边栏使用,如要调用条数,修改'pageSize=8'中的数字就可以
<?php $this->widget('Widget_Contents_Post_Recent', 'pageSize=8')->to($posts); ?>
<?php if ($posts->have()): ?>
<div class="simple-recent-posts">
<h4 class="sidebar-title">最近更新</h4>
<ul class="recent-list">
<?php while ($posts->next()): ?>
<li class="recent-item">
<a href="<?php $posts->permalink(); ?>" class="recent-link">
<span class="post-title-text"><?php $posts->title(); ?></span>
<span class="post-date"><?php $posts->date('n/j'); ?></span>
</a>
</li>
<?php endwhile; ?>
</ul>
</div>
<style>
.simple-recent-posts {
background: white;
border-radius: 8px;
padding: 20px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
}
.sidebar-title {
margin: 0 0 15px 0;
font-size: 1.1rem;
color: #2c3e50;
padding-bottom: 10px;
border-bottom: 1px dashed #e0e6ed;
}
.recent-list {
list-style: none;
padding: 0;
margin: 0;
}
.recent-item {
margin-bottom: 8px;
}
.recent-link {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 12px;
text-decoration: none;
color: #4a5568;
background: #f7fafc;
border-radius: 6px;
transition: all 0.2s;
border-left: 3px solid transparent;
}
.recent-link:hover {
background: #edf2f7;
color: #2d3748;
border-left-color: #4299e1;
transform: translateX(3px);
}
.post-title-text {
flex: 1;
font-size: 0.95rem;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
padding-right: 10px;
}
.post-date {
font-size: 0.8rem;
color: #a0aec0;
background: #e2e8f0;
padding: 2px 8px;
border-radius: 10px;
min-width: 40px;
text-align: center;
}
</style>
<?php endif; ?>