您的购物车目前是空的!
wp_get_archives函数可以让是实现年度归档、月度归档、周归档、日归档等等,配合 Limit 使用限定显示数量,甚至可以制作网站地图!wp_get_archives()可用在模板中的任何位置。
WordPress的widget里提供的文章索引模板,他可以让你的WordPress博客的侧边栏按月度存档,方便读者,方便搜索引擎。但默认显示的是所有月度归档,这对有着两年,甚至两年以上历史的老博客来说,无疑是一种负担。那长长的一竖排,无表情的竖在那里,显的呆板缺少灵气;再者较老的日志也不能适应现在的需要。当一片技术日志让留言者被挖祖坟般挖了出来,你几乎都产生了这日志是否是你写的这种错觉时,隐藏部分月度归档显得尤为重要了。
Table of Contents
<?php wp_get_archives( $args ); ?>
<?php $args = array(
'type' => 'monthly',
'limit' => '',
'format' => 'html',
'before' => '',
'after' => '',
'show_post_count' => false,
'echo' => 1,
'order' => 'DESC'
);
wp_get_archives( $args ); ?>
默认情况下,使用显示:
type
limit
format
<li>
<select>
<option>
<link>
before
after
show_post_count
echo
order
1、以月归档方式显示十二个月的归档
按月份显示存档列表,只显示最后十二个月的文章。
<?php wp_get_archives( array( 'type' => 'monthly', 'limit' => 12 ) ); ?>
2、过去十六天
显示归档列表的日期,显示的最后十六天。
<?php wp_get_archives( array( 'type' => 'daily', 'limit' => 16) ); ?>
3、最后二十个文章
显示最近二十个最新文章标题所列出的存档列表。
<?php wp_get_archives( array( 'type' => 'postbypost', 'limit' => 20, 'format' => 'custom' ) ); ?>
4、下拉框
显示每月档案的下拉框,在选定的标签,并统计每月日志数量。
<select name="archive-dropdown" onchange="document.location.href=this.options[this.selectedIndex].value;">
<option value=""><?php echo esc_attr( __( 'Select Month' ) ); ?></option>
<?php wp_get_archives( array( 'type' => 'monthly', 'format' => 'option', 'show_post_count' => 1 ) ); ?>
</select>
5、显示所有文章按字母顺序
显示所有文章按标题方式排列显示所有日志,特别是如果你想有一个日志档案,就像一个sitemap。
<?php wp_get_archives('type=alpha'); ?>
wp_get_archives() is located in wp-includes/general-template.php.