I would like to break up a sidebar over three containers. Each container should hold up to three widgets of the sidebar. Therefore, I need to find the HTML for only the widgets 0 to 2, 3 to 5 and 6 to 8 separately.
Normally, I would use dynamic_sidebar()
to display the sidebar, but this function doesn't accept parameters to specify that I only want a range of the widgets of the sidebar. Moreover, I found wp_get_sidebars_widgets()
, but it is not intended to use for themes.
How can I get only the widgets in a given range of a dynamic sidebar? For example, this is what I think of.
// functions.php
// display range of widgets of a sidebar
function dynamic_sidebar_range($name, $from, $to)
{
$widgets = get_dynamic_sidebar($name); // this function doesn't exist!
for ($i = $from; $i < count($widgets) && $i < $to; ++$i ) {
$widget = $widgets[$i];
echo $widget['before_widget']
. $widget['before_title']
. $widget['title']
. $widget['after_title']
. $widget['content']
. $widget['after_widget'];
}
}
// frontpage.php
// consists of blocks of three posts or widgets alternatingly
for ($sections = 0; $sections < 3; ++$sections) {
// display three posts
for ($i = 0; $i < 3 && have_posts(); ++$i) {
the_post();
// ...
}
// display three widgets
$from = $sections * 3;
$to = $from + 3;
dynamic_sidebar_range('name', $from, $to);
}