WordPress文章归档小工具是WordPress内置小工具之一,文章归档支持我们以日期的形式来分类存储文章,WordPress文章归档小工具在网站侧边栏以月度存档的形式展示网站的文章存档。
文章归档URL格式:
1.按年存档
http://www.wptoutiao.com/date/2017
2.按月存档
http://www.wptoutiao.com/date/2017/05
3.按日存档
http://www.wptoutiao.com/date/2017/05/09
注:WordPress通过页面判断函数is_archive()来判断当前页面是否是归档页面。
WordPress文章归档小工具使用介绍
在网站【后台-外观-小工具】中找到文章归档小工具,将它拖到想要展示的侧边栏中。
设置选项:
1.文章归档小工具标题
2.是否以下拉菜单的形式显示文章存档
3.是否显示文章存档的文章数量
WordPress文章归档小工具前端展示
预览显示的不是以下拉菜单但是显示文章数量的WordPress文章归档。
WordPress文章归档小工具源码介绍
源码位置:wp-includes\widgets\class-wp-widget-archives.php
源代码:(since 4.4.0)
'widget_archive',
'description' => __( 'A monthly archive of your site’s Posts.' ),
'customize_selective_refresh' => true,
);
parent::__construct('archives', __('Archives'), $widget_ops);
}
/**
* Outputs the content for the current Archives widget instance.
*
* @since 2.8.0
* @access public
*
* @param array $args Display arguments including 'before_title', 'after_title',
* 'before_widget', and 'after_widget'.
* @param array $instance Settings for the current Archives widget instance.
*/
public function widget( $args, $instance ) {
$c = ! empty( $instance['count'] ) ? '1' : '0';
$d = ! empty( $instance['dropdown'] ) ? '1' : '0';
/** This filter is documented in wp-includes/widgets/class-wp-widget-pages.php */
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Archives' ) : $instance['title'], $instance, $this->id_base );
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
if ( $d ) {
$dropdown_id = "{$this->id_base}-dropdown-{$this->number}";
?>
-
'monthly',
'show_post_count' => $c
) ) );
?>
id="get_field_id('dropdown'); ?>" name="get_field_name('dropdown'); ?>" />
id="get_field_id('count'); ?>" name="get_field_name('count'); ?>" />
WordPress文章归档小工具也支持标题的过滤,更多自定义我们在后面的文章中会介绍给大家。
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友: