Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $dynamic_widget_areas = array (
- 'sidebar-21' => __( 'Page Specific Sidebar 1', 'pietergoosen' ),
- 'sidebar-22' => __( 'Page Specific Sidebar 2', 'pietergoosen' ),
- 'sidebar-23' => __( 'Page Specific Sidebar 3', 'pietergoosen' ),
- 'sidebar-24' => __( 'Page Specific Sidebar 4', 'pietergoosen' ),
- 'sidebar-25' => __( 'Page Specific Sidebar 5', 'pietergoosen' ),
- 'sidebar-26' => __( 'Page Specific Sidebar 6', 'pietergoosen' ),
- 'sidebar-27' => __( 'Page Specific Sidebar 7', 'pietergoosen' ),
- 'sidebar-28' => __( 'Page Specific Sidebar 8', 'pietergoosen' ),
- 'sidebar-29' => __( 'Page Specific Sidebar 9', 'pietergoosen' ),
- 'sidebar-30' => __( 'Page Specific Sidebar 10', 'pietergoosen' ),
- );
- foreach ( $dynamic_widget_areas as $id => $dynamic_widget_area ) {
- register_sidebar(
- array (
- 'name' => __( $dynamic_widget_area, 'pietergoosen' ),
- 'id' => $id,
- 'description' => __( 'Page specific sidebars above the content sidebar', 'pietergoosen' ),
- 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
- 'after_widget' => '</aside>',
- 'before_title' => '<h1 class="widget-title">',
- 'after_title' => '</h1>',
- ));
- }
- }
- add_action( 'widgets_init', 'pietergoosen_widgets_init' );
- // Add dynamic sidebars
- add_action('admin_init', 'sidebar_init');
- add_action('save_post', 'save_sidebar_link');
- function sidebar_init(){
- add_meta_box("sidebar_meta", "Sidebar options", "sidebar_link", "page", "side", "default");
- }
- function sidebar_link(){
- global $post, $dynamic_widget_areas;
- $custom = get_post_custom($post->ID);
- $link = $custom["_sidebar"][0];
- ?>
- <div class="link_header">
- <?
- echo '<select name="link" class="sidebar-selection">';
- echo '<option>Choose Sidebar</option>';
- echo '<option>No sidebars to choose from</option>';
- foreach ( $dynamic_widget_areas as $list ){
- if($link == $list){
- echo '<option value="'.$list.'" selected="true">'.$list.'</option>';
- }else{
- echo '<option value="'.$list.'">'.$list.'</option>';
- }
- }
- echo '</select><br />';
- ?>
- </div>
- <p>Choose the sidebar to use with this page.</p>
- <?php
- }
- function save_sidebar_link(){
- global $post;
- if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {return $post->ID;}
- update_post_meta($post->ID, "_sidebar", $_POST["link"]);
- }
- add_action('admin_head', 'sidebar_css');
- function sidebar_css() {
- echo'
- <style type="text/css">
- .sidebar-selection{width:100%;}
- </style>
- ';
- }
Advertisement
Add Comment
Please, Sign In to add comment