所以我用以下代码注册了我的小部件区域:
register_sidebar( array(
\'name\' => __( \'Posts Widget Area\', \'ikos\' ),
\'id\' => \'primary-widget-area\',
\'class\' => \'post-w\',
\'description\' => __( \'Shown only in Blog Posts, Archives, Categories, etc.\', \'ikos\' ),
\'before_widget\' => \'<li id="%1$s" class="widget-container %2$s">\',
\'after_widget\' => \'</li>\',
\'before_title\' => \'<h3 class="widget-title">\',
\'after_title\' => \'</h3>\',
) );
注意,我添加了一个类。我想“抓取”这个类(动态)并对所有侧边栏使用相同的代码。。。类似于:
<div id="sidebar" class="
HERE THE CODE THAT GRABS THE CLASS" role="complementary">
但我不知道如何编写这个小东西。请提供帮助:)
EDIT我使用这段代码在函数中“包装”侧栏。php
// Before Sidebar - do_action(\'st_before_sidebar\')
// call up the action
if ( !function_exists( \'before_sidebar\' ) ) {
function before_sidebar($columns) {
if (empty($columns)) {
// Set the default
$columns = \'five\';
} else {
// Check the function for a returned variable
$columns = $columns;
}
// Apply the markup
echo \'<div id="sidebar" class="\'.$columns.\' columns" role="complementary">\';
}
} //endif
// create our hook
add_action( \'ikos_before_sidebar\', \'before_sidebar\');
// After Sidebar
if ( !function_exists( \'after_sidebar\' ) ) {
function after_sidebar() {
// Additional Content could be added here
echo \'</div><!-- #sidebar -->\';
}
} //endif
add_action( \'ikos_after_sidebar\', \'after_sidebar\');
EDIT 2
在页面中,我只调用侧边栏
get_sidebar(\'page\');
和侧边栏页面内。php我调用在函数中编写的before和after操作。我需要为类添加一个动态变量。。。有没有办法做到这一点?