the_widget ( $widget, $instance = array(), $args = array() )
- 参数
-
-
(string)
$widget
The widget’s PHP class name (see class-wp-widget.php).- Required: 是
-
(array)
$instance
Optional. The widget’s instance settings. Default empty array.- Required: 否
- Default: array()
-
(array)
$args
{ Optional. Array of arguments to configure the display of the widget. @type string $before_widget HTML content that will be prepended to the widget’s HTML output. Default ``. @type string $before_title HTML content that will be prepended to the widget’s title when displayed. Default `
`. @type string $after_title HTML content that will be appended to the widget’s title when displayed. Default `
`. }
- Required: 否
- Default: array()
-
(string)
- 定义位置
-
-
wp-includes/widgets.php
, line 1206
-
wp-includes/widgets.php
- 引入
- 2.8.0
- 弃用
- –
Output an arbitrary widget as a template tag.
function the_widget( $widget, $instance = array(), $args = array() ) { global $wp_widget_factory; if ( ! isset( $wp_widget_factory->widgets[ $widget ] ) ) { _doing_it_wrong( __FUNCTION__, sprintf( /* translators: %s: register_widget() */ __( 'Widgets need to be registered using %s, before they can be displayed.' ), 'register_widget()
' ), '4.9.0' ); return; } $widget_obj = $wp_widget_factory->widgets[ $widget ]; if ( ! ( $widget_obj instanceof WP_Widget ) ) { return; } $default_args = array( 'before_widget' => ' ', 'before_title' => '', 'after_title' => '
', ); $args = wp_parse_args( $args, $default_args ); $args['before_widget'] = sprintf( $args['before_widget'], $widget_obj->widget_options['classname'] ); $instance = wp_parse_args( $instance ); /** This filter is documented in wp-includes/class-wp-widget.php */ $instance = apply_filters( 'widget_display_callback', $instance, $widget_obj, $args ); if ( false === $instance ) { return; } /** * Fires before rendering the requested widget. * * @since 3.0.0 * * @param string $widget The widget's class name. * @param array $instance The current widget instance's settings. * @param array $args An array of the widget's sidebar arguments. */ do_action( 'the_widget', $widget, $instance, $args ); $widget_obj->_set( -1 ); $widget_obj->widget( $args, $instance ); }
声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。