这很好用,但这对我来说很傻,因为我甚至不知道要搜索什么(或者问题的标题是否正确),以了解如何完成不重复$slide_panels
数组低于它的christina_slide_in_panels()
函数及其外部。
可悲的是,这个问题已经结束,但史蒂夫的回答是在评论中。通过阅读“重复”的接受后答案回答问题没有回答,至少没有具体说明。
//* register slide panels
$slide_panels = array (
'slide-1' => 'Slide Panel One',
'slide-2' => 'Slide Panel Two',
'slide-3' => 'Slide Panel Three',
'slide-4' => 'Slide Panel Four',
);
foreach ( $slide_panels as $id => $slide_panel) {
register_sidebar(
array (
'name' => __( $slide_panel, 'christina' ),
'id' => $id,
'before_widget' => '<aside id="%1$s" class="slide-widget %2$s">',
'after_widget' => '</aside>',
'before_title' => '<h3 class="slide-widget-title">',
'after_title' => '</h3>',
));
}
//* create the panels
function christina_slide_in_panels() {
//======== > HOW TO NOT REPEAT THIS < ========
$slide_panels = array (
'slide-1' => 'Slide Panel One',
'slide-2' => 'Slide Panel Two',
'slide-3' => 'Slide Panel Three',
'slide-4' => 'Slide Panel Four',
);
echo '<!-- begin slide panels --><div class="slide-in-panels-parent">';
foreach ( $slide_panels as $id => $slide_panel) {
if ( is_active_sidebar( $id ) ) {
echo '<div class="slide-panel" id="'.$id.'" aria-expanded="false" aria-hidden="true">';
// id used on the toggle to get this slide in
dynamic_sidebar( $id );
echo '</div><!-- close '.$id.' -->';
}
//end endif;
}
//end foreach
echo '</div><!-- end slide panels -->';
//close parent;
}
add_action('genesis_after', 'christina_slide_in_panels');