wp_get_archives函数可以让是实现年度归档、月度归档、周归档、日归档等等,配合 Limit 使用限定显示数量,甚至可以制作网站地图!wp_get_archives()可用在模板中的任何位置。
用法
<?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 ); ?>
默认情况下,使用显示:
- ◆ 每月档案链接显示
- ◆ 显示所有档案(不限数字)
- ◆ 依次在HTML列表显示档案
- ◆ 没有显示之前或之后的每一个链接
- ◆ 不显示数量的帖子
参数
type
- (字符串) 显示列表的类型。默认的WordPress设置。有效值:
- ■ yearly
- ■ monthly – 默认值
- ■ daily
- ■ weekly
- ■ postbypost (按照发布时期排序)
- ■ alpha (例如 postbypost 但是文章按照文章标题排序)
limit
- (整数) 获得的文章数量,默认没有限制。
format
- ◆ (字符串) 文章的列表格式。有效值:
- ◆ html – 在HTML的列表中
<li>
- 标签和前后字符串。这是默认的。
- ◆ option – 在选项
<select>
- 标签或者是下来菜单选项中
<option>
- ◆ link – 内链
<link>
- 标签中。
- ◆ custom – 自定义列表使用前后字符串。
before
- (字符串) 在使用该链接时文本到地方 html 或者 custom 格式选项。没有默认值。
after
- (字符串) 在使用该链接时文本到地方 html 或者 custom 格式选项。没有默认值。
show_post_count
- (布尔值) 是否在列表中显示的文章的数目。除了使用所有类型 ‘postbypost’.
- ■ 1 (True)
- ■ 0 (False) – 默认值
echo
- (布尔值) 返回值是否直接显示在网页中。
- ◆ 1 (True) – 默认值
- ◆ 0 (False)
order
- (string) 如何排列查询到的文章 (since Version 3.5)
- ■ ASC – 升序排列 (A-Z).
- ■ DESC – 降序排列 (Z-A) – 默认值
wp_get_archives调用实例:
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.
WordPress日记主要承接WordPress主题定制开发、PSD转WordPress、WordPress仿站以及以WordPress为管理后端的小程序、APP,我们一直秉持“做一个项目,交一个朋友”的理念,希望您是我们下一个朋友。如果您有WordPress主题开发需求,可随时联系QQ:919985494
上一篇:已是最新文章
相关文章
WordPress获取指定文章所有自定义字段函数get_post_custom()
在WordPress主题或插件开发过程中,我们可能会需要获取…WordPress获取分类信息函数WP_Term_Query()介绍及使用方法
在《获取WordPress指定条件的分类列表函数get_te…WordPress更新和添加文章自定义字段函数update_post_meta()
平时在WordPress主题开发中我们经常需要去更新或者添加…wordpress获取文章特色图像路径函数wp_get_attachment_image_src()
特色图像是wordpress主要的文章缩略图功能,几乎全部w…WordPress添加自定义字段到文章函数add_post_meta()
在我们开发WordPress主题或WordPress插件的时…WordPress中如何获取指定用户角色的文章
今天,有用户在我们的WordPress中文社区问答区提问说,…