the_widget()
the_widget( string $widget, array $instance = array(), …
the_widget( string $widget, array $instance = array(), array $args = array() )
输出任意小部件作为模板标记。
Output an arbitrary widget as a template tag.
输出任意小部件作为模板标记。
Output an arbitrary widget as a template tag.
目录锚点:#源码#笔记
源码(Source)
/**
* Output an arbitrary widget as a template tag.
*
* @since 2.8.0
*
* @global WP_Widget_Factory $wp_widget_factory
*
* @param string $widget The widget's PHP class name (see default-widgets.php).
* @param array $instance Optional. The widget's instance settings. Default empty array.
* @param 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 ``, where `%s` is the widget's class name.
* @type string $after_widget HTML content that will be appended 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 ``.
* }
*/
function the_widget( $widget, $instance = array(), $args = array() ) {
global $wp_widget_factory;
$widget_obj = $wp_widget_factory->widgets[$widget];
if ( ! ( $widget_obj instanceof WP_Widget ) ) {
return;
}
$before_widget = sprintf('', $widget_obj->widget_options['classname'] );
$default_args = array( 'before_widget' => $before_widget, 'after_widget' => "", 'before_title' => '', 'after_title' => '' );
$args = wp_parse_args($args, $default_args);
$instance = wp_parse_args($instance);
/**
* 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);
}| 更新版本 | 源码位置 | 使用 | 被使用 |
|---|---|---|---|
| 2.8.0 | wp-includes/widgets.php | 2 | 1 |
笔记(Notes)
显示具有默认设置的小部件:
类别:WordPress 函数手册、
本文收集自互联网,转载请注明来源。
如有侵权,请联系 wper_net@163.com 删除。



还没有任何评论,赶紧来占个楼吧!