注册侧栏只是一个函数调用,没有理由不能在某些逻辑上运行它。以下是我在当前主题中编写(并使用)的代码:
$pages = get_pages();
foreach ( $pages as $page ) {
register_sidebar( array(
\'name\' => "Page: {$page->post_title}",
\'id\' => "sidebar-page-{$page->post_name}",
\'description\' => "Widgetized area after content of \\"{$page->post_title}\\" page.",
\'before_widget\' => \'<div id="%1$s" class="widget %2$s">\',
\'after_widget\' => \'</div>\'
));
}
然后,在页面模板调用侧栏中,遵循相同的ID约定,就可以设置了。