下面介绍一种常见使用的存档方式,先看代码:

<div class=”archives”>
<?php
$previous_year = $year = 0;
$previous_month = $month = 0;
$ul_open = false;

$myposts = get_posts(‘numberposts=-1&orderby=post_date&order=DESC’);

foreach($myposts as $post) :
setup_postdata($post);

$year = mysql2date(‘Y’, $post->post_date);
$month = mysql2date(‘n’, $post->post_date);
$day = mysql2date(‘j’, $post->post_date);

if($year != $previous_year || $month != $previous_month) :
if($ul_open == true) :
echo ‘</table>’;
endif;

echo ‘<h3>’; echo the_time(‘F Y’); echo ‘</h3>’;
echo ‘<table>’;
$ul_open = true;

endif;

$previous_year = $year; $previous_month = $month;
?>
<tr>
<td width=”40″ style=”text-align:right;”><?php the_time(‘j’); ?>日</td>
<td width=”400″><a href=”<?php the_permalink(); ?>”><?php the_title(); ?></a></td>
<td width=”120″><a class=”comm” href=”<?php comments_link(); ?>” title=”查看 <?php the_title(); ?> 的评论”><?php comments_number(‘0’, ‘1’, ‘%’); ?>人评论</a></td>
<td width=”120″><span class=”view”><?php if(function_exists(‘the_views’)) the_views(); ?>次浏览</span></td>
</tr>
<?php endforeach; ?>
</table>
</div>

复制以上代码到你希望显示的页面,或者自行后台-页面-新建页面。
显示样式:

<style type=”text/css”>
.archives td{padding: 6px 10px 8px;border-bottom: solid 1px #eee}
.archives table{padding:10px 0 20px}
.meta-tit{border-bottom: solid 1px #e6e6e6;padding: 0 0 10px;margin-bottom: 20px}
</style>

如不喜欢以上样式可以自行修改。
其实Wordpress存档页面就是这么简单,如果你安装了wp-postviews插件,存档页面中将显示文章浏览次数,很不错吧!

1.《WordPress 存档页面Archive.php模板制作》援引自互联网,旨在传递更多网络信息知识,仅代表作者本人观点,与本网站无关,侵删请联系页脚下方联系方式。

2.《WordPress 存档页面Archive.php模板制作》仅供读者参考,本网站未对该内容进行证实,对其原创性、真实性、完整性、及时性不作任何保证。

3.文章转载时请保留本站内容来源地址,https://www.cxvn.com/study/122.html