WP提供了页面功能给我们创建一些静态页面,有关问题请查看WordPress新建页面,今天我们来看下WordPress提供的另外一个小工具,让我们在侧边栏展示网站的页面列表。
WordPress页面小工具使用介绍
在网站【后台-外观-小工具】中找到页面小工具,将它拖到想要展示的侧边栏中。
页面小工具的设置包括(页面标题,排序依据,排除页面),我们可以像大部分小工具一样给页面小工具设置一个自定义标题,可以设置页面列表的排序依据(页面标题,页面排序和页面ID排序),当然我们还可以排除我们不想显示的页面,只要把(页面ID,多个ID请用英文逗号(,)或中文顿号(、)隔开)填入除了选项框中即可。
WordPress页面小工具源码介绍
源码位置:wp-includes\widgets\class-wp-widget-pages.php
源代码:(since 4.4.0)
'widget_pages',
'description' => __( 'A list of your site’s Pages.' ),
'customize_selective_refresh' => true,
);
parent::__construct( 'pages', __( 'Pages' ), $widget_ops );
}
/**
* Outputs the content for the current Pages 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 Pages widget instance.
*/
public function widget( $args, $instance ) {
/**
* Filters the widget title.
*
* @since 2.6.0
*
* @param string $title The widget title. Default 'Pages'.
* @param array $instance An array of the widget's settings.
* @param mixed $id_base The widget ID.
*/
$title = apply_filters( 'widget_title', empty( $instance['title'] ) ? __( 'Pages' ) : $instance['title'], $instance, $this->id_base );
$sortby = empty( $instance['sortby'] ) ? 'menu_order' : $instance['sortby'];
$exclude = empty( $instance['exclude'] ) ? '' : $instance['exclude'];
if ( $sortby == 'menu_order' )
$sortby = 'menu_order, post_title';
/**
* Filters the arguments for the Pages widget.
*
* @since 2.8.0
*
* @see wp_list_pages()
*
* @param array $args An array of arguments to retrieve the pages list.
*/
$out = wp_list_pages( apply_filters( 'widget_pages_args', array(
'title_li' => '',
'echo' => 0,
'sort_column' => $sortby,
'exclude' => $exclude
) ) );
if ( ! empty( $out ) ) {
echo $args['before_widget'];
if ( $title ) {
echo $args['before_title'] . $title . $args['after_title'];
}
?>
WordPress页面小工具源码给我们提供的过滤器:
1.widget_title
2.widget_pages_args
我们可以利用这两个过滤器来自定义页面小工具的显示内容,今天就不多说了,有时间再总结下WordPress页面小工具的自定义内容。
感觉本站内容不错,读后有收获?小额赞助
还可以分享文章给好友:
我还没用过这个小工具呢,我去看看是啥效果。