我一直在阅读Wordpress Source,试图更好地理解动态侧边栏的呈现方式。
然而,我正处于一个棘手的问题......
894 | do_action( 'dynamic_sidebar', $wp_registered_widgets[$id] );
我无法找到定义add_action('dynamic_sidebar',...)的位置。没有那部分,我会在发生的事情中迷失方向。
请参阅此处的代码:
为了提供更多上下文,我试图弄清楚如何从特定的侧边栏中获取一组小部件,从那里,我需要知道如何渲染该数组中的每个小部件。
我需要比dynamic_sidebar(...);
给予我更好的控制
答案 0 :(得分:1)
那么,该特定行允许您访问每个已注册的Widget属性,并使用它:
<?php
/* Plugin Name: Test registered widgets */
add_action( 'dynamic_sidebar', 'sidebar_widgets_so_18666065' );
/**
* As this is an action hook, we don't return nothing
* use the passed values to do your stuff
*/
function sidebar_widgets_so_18666065( $registered_widget )
{
# Each registered widget passes the following array
/*
$registered_widget = Array
(
[name] => Meta
[id] => meta-2
[callback] => Array
(
[0] => WP_Widget_Meta Object
(
[id_base] => meta
[name] => Meta
[widget_options] => Array
(
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
[control_options] => Array
(
[id_base] => meta
)
[number] => 2
[id] => meta-2
[updated] =>
[option_name] => widget_meta
)
[1] => display_callback
)
[params] => Array
(
[0] => Array
(
[number] => 2
)
)
[classname] => widget_meta
[description] => Log in/out, admin, feed and WordPress links
)
*/
}
Relevant search query在WordPress答案。