Problems adding and removing sidebars.
-
I am developing a website with over 40 sidebars at this moment. I want to keep my sidebars in alphabetical order in the widgets.php page so that my client will be able to find the correct sidebar with ease. I’m finding that when I add a new sidebar (say in the middle of my sidebar list) in the functions.php page and upload it to my server, the content that was already on the existing sidebars (listed in functions.php below the new sidebar) will be erased.
So, if I want to add a new sidebar, I’m forced to place it at the bottom of the sidebar list in functions.php so that my existing content doesn’t get erased. I’m also realizing that if I want to remove a sidebar from the list in functions.php it’s going to erase the content in the existing sidebars.
Here is my code in fuctions. php
<?php if ( function_exists('register_sidebars') ) register_sidebar; /*TELLS HOW MANY SIDEBARS TO ADD*/ { register_sidebar(array( 'name' => 'Homepage -- Left Sidebar', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Homepage -- Right Sidebar', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Homepage -- Lower Left Box', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Homepage -- Lower Right Box', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Global -- Right Sidebar', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Global -- Right Sidebar - Ads', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Global -- Right Sidebar - Lower', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Global -- Left Sidebar', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- About', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Personal Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Business Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Loans', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Our Community', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Investments & Insurance', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- Privacy & Security', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- No Category Option 1', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- No Category Option 2', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- No Category Option 3', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Top Banner -- No Category Option 4', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- About', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Personal Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Business Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Loans', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Our Community', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Investments & Insurance', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- Privacy & Security', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- No Category Option 1', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- No Category Option 2', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- No Category Option 3', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Left Sidebar -- No Category Option 4', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- About', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Personal Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Business Banking', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Loans', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Our Community', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Investments & Insurance', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- Privacy & Security', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- No Category Option 1', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- No Category Option 2', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- No Category Option 3', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); register_sidebar(array( 'name' => 'Right Sidebar -- No Category Option 4', 'before_widget' => '', 'after_widget' => '', 'before_title' => '<h2 class="widgettitle">', 'after_title' => '</h2>',)); } $themename = "Video and Advertisment"; $shortname = "revnews"; $options = array ( array( "name" => "General Settings", "type" => "heading"), array( "name" => "RSS Feedburner ID", "desc" => "Learn how to find your Feedburner ID by checking out the <a href='https://www.hccadvertising.com/tutorials'>tutorials</a> page", "id" => $shortname."_feedburner_id", "std" => "Enter Feedburner Email Subscribe ID Here", "type" => "text"), array( "name" => "468x60 AdSense Code", "desc" => "This is for the 468x60 Google AdSense banner in between the single post and comments section.<br /><br />", "id" => $shortname."_adsense_468", "std" => "Enter Google AdSense Code Here", "type" => "textarea"), array( "name" => "300x250 AdSense Code", "desc" => "This is for the 300x250 Google AdSense banner in between the single post and comments section.<br /><br />", "id" => $shortname."_adsense_300", "std" => "Enter Google AdSense Code Here", "type" => "textarea"), array( "name" => "120x600 Banner Ad", "desc" => "This is for the the 120x600 ad banner in the sidebar.", "id" => $shortname."_ad_120", "std" => "Enter 120x600 Banner Code Here", "type" => "textarea"), array( "name" => "Weekly Videocast Video", "desc" => "This is for the featured video in the sidebar. Use YouTube Videos in this section.<br />Recommended size for the video is 300x250, so don't forget to change that from the embedded video code.<br /><br />", "id" => $shortname."_you_tube", "id" => $shortname."_video", "std" => "Enter Embedded Video Code Here", "type" => "textarea"), array( "name" => "Plymouth Branch Video Code", "desc" => "This is for the featured video in the sidebar. Use YouTube Videos in this section.<br />Recommended size for the video is 300x250, so don't forget to change that from the embedded video code.<br /><br />", "id" => $shortname."_you_tube", "id" => $shortname."_plymouth", "std" => "Enter Embedded Video Code Here", "type" => "textarea"), array( "name" => "Plymouth Branch Ad - 300x250", "desc" => "This is for the 300x250 Ad banner in between the single post and comments section.<br /><br />", "id" => $shortname."_adsense_300_plymouth", "std" => "Enter Image Code Here", "type" => "textarea"), array( "name" => "Plymouth Branch Officer", "desc" => "This is for Plymouth Branch Officer Information. It goes above the branch video<br /><br />", "id" => $shortname."_branchofficer_plymouth", "std" => "Enter Text here.", "type" => "textarea"), array( "name" => "Plymouth Branch Location", "desc" => "This is for Plymouth Branch Location Information. It goes above the branch video<br /><br />", "id" => $shortname."_branchlocation_plymouth", "std" => "Enter Text here.", "type" => "textarea"), array( "name" => "Plymouth Branch Phone", "desc" => "This is for Plymouth Branch Phone Information. It goes above the branch video<br /><br />", "id" => $shortname."_branchphone_plymouth", "std" => "Enter Text here.", "type" => "textarea"), ); function mytheme_add_admin() { global $themename, $shortname, $options; if ( $_GET['page'] == basename(__FILE__) ) { if ( 'save' == $_REQUEST['action'] ) { foreach ($options as $value) { if($value['type'] != 'multicheck'){ update_option( $value['id'], $_REQUEST[ $value['id'] ] ); }else{ foreach($value['options'] as $mc_key => $mc_value){ $up_opt = $value['id'].'_'.$mc_key; update_option($up_opt, $_REQUEST[$up_opt] ); } } } foreach ($options as $value) { if($value['type'] != 'multicheck'){ if( isset( $_REQUEST[ $value['id'] ] ) ) { update_option( $value['id'], $_REQUEST[ $value['id'] ] ); } else { delete_option( $value['id'] ); } }else{ foreach($value['options'] as $mc_key => $mc_value){ $up_opt = $value['id'].'_'.$mc_key; if( isset( $_REQUEST[ $up_opt ] ) ) { update_option( $up_opt, $_REQUEST[ $up_opt ] ); } else { delete_option( $up_opt ); } } } } header("Location: themes.php?page=functions.php&saved=true"); die; } else if( 'reset' == $_REQUEST['action'] ) { foreach ($options as $value) { if($value['type'] != 'multicheck'){ delete_option( $value['id'] ); }else{ foreach($value['options'] as $mc_key => $mc_value){ $del_opt = $value['id'].'_'.$mc_key; delete_option($del_opt); } } } header("Location: themes.php?page=functions.php&reset=true"); die; } } add_theme_page($themename." Options", "$themename Options", 'edit_themes', basename(__FILE__), 'mytheme_admin'); } function mytheme_admin() { global $themename, $shortname, $options; if ( $_REQUEST['saved'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings saved.</strong></p></div>'; if ( $_REQUEST['reset'] ) echo '<div id="message" class="updated fade"><p><strong>'.$themename.' settings reset.</strong></p></div>'; ?> <div class="wrap"> <h2><?php echo $themename; ?> options</h2> <form method="post"> <table class="optiontable"> <?php foreach ($options as $value) { switch ( $value['type'] ) { case 'text': option_wrapper_header($value); ?> <input style="width:400px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" type="<?php echo $value['type']; ?>" value="<?php if ( get_settings( $value['id'] ) != "") { echo get_settings( $value['id'] ); } else { echo $value['std']; } ?>" /> <?php option_wrapper_footer($value); break; case 'select': option_wrapper_header($value); ?> <select style="width:240px;" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>"> <?php foreach ($value['options'] as $option) { ?> <option<?php if ( get_settings( $value['id'] ) == $option) { echo ' selected="selected"'; } elseif ($option == $value['std']) { echo ' selected="selected"'; } ?>><?php echo $option; ?></option> <?php } ?> </select> <?php option_wrapper_footer($value); break; case 'textarea': $ta_options = $value['options']; option_wrapper_header($value); ?> <textarea name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" style="width:400px;height:100px;"><?php if( get_settings($value['id']) != "") { echo stripslashes(get_settings($value['id'])); }else{ echo $value['std']; }?></textarea> <?php option_wrapper_footer($value); break; case "radio": option_wrapper_header($value); foreach ($value['options'] as $key=>$option) { $radio_setting = get_settings($value['id']); if($radio_setting != ''){ if ($key == get_settings($value['id']) ) { $checked = "checked=\"checked\""; } else { $checked = ""; } }else{ if($key == $value['std']){ $checked = "checked=\"checked\""; }else{ $checked = ""; } }?> <input type="radio" name="<?php echo $value['id']; ?>" value="<?php echo $key; ?>" <?php echo $checked; ?> /><?php echo $option; ?><br /> <?php } option_wrapper_footer($value); break; case "checkbox": option_wrapper_header($value); if(get_settings($value['id'])){ $checked = "checked=\"checked\""; }else{ $checked = ""; } ?> <input type="checkbox" name="<?php echo $value['id']; ?>" id="<?php echo $value['id']; ?>" value="true" <?php echo $checked; ?> /> <?php option_wrapper_footer($value); break; case "multicheck": option_wrapper_header($value); foreach ($value['options'] as $key=>$option) { $pn_key = $value['id'] . '_' . $key; $checkbox_setting = get_settings($pn_key); if($checkbox_setting != ''){ if (get_settings($pn_key) ) { $checked = "checked=\"checked\""; } else { $checked = ""; } }else{ if($key == $value['std']){ $checked = "checked=\"checked\""; }else{ $checked = ""; } }?> <input type="checkbox" name="<?php echo $pn_key; ?>" id="<?php echo $pn_key; ?>" value="true" <?php echo $checked; ?> /><label for="<?php echo $pn_key; ?>"><?php echo $option; ?></label><br /> <?php } option_wrapper_footer($value); break; case "heading": ?> <tr valign="top"> <td colspan="2" style="text-align: center;"><h3><?php echo $value['name']; ?></h3></td> </tr> <?php break; default: break; } } ?> </table> <p class="submit"> <input name="save" type="submit" value="Save changes" /> <input type="hidden" name="action" value="save" /> </p> </form> <form method="post"> <p class="submit"> <input name="reset" type="submit" value="Reset" /> <input type="hidden" name="action" value="reset" /> </p> </form> <?php } function option_wrapper_header($values){ ?> <tr valign="top"> <th scope="row"><?php echo $values['name']; ?>:</th> <td> <?php } function option_wrapper_footer($values){ ?> </td> </tr> <tr valign="top"> <td> </td><td><small><?php echo $values['desc']; ?></small></td> </tr> <?php } function mytheme_wp_head() { $stylesheet = get_option('revmag_alt_stylesheet'); if($stylesheet != ''){?> <?php } } add_action('wp_head', 'mytheme_wp_head'); add_action('admin_menu', 'mytheme_add_admin'); ?> <?php function the_content_limit($max_char, $more_link_text = '(more...)', $stripteaser = 0, $more_file = '') { $content = get_the_content($more_link_text, $stripteaser, $more_file); $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = strip_tags($content); if (strlen($_GET['p']) > 0) { echo "<p>"; echo $content; echo " <a href='"; the_permalink(); echo "'>"."Read More →</a>"; echo "</p>"; } else if ((strlen($content)>$max_char) && ($espacio = strpos($content, " ", $max_char ))) { $content = substr($content, 0, $espacio); $content = $content; echo "<p>"; echo $content; echo "..."; echo " <a href='"; the_permalink(); echo "'>".$more_link_text."</a>"; echo "</p>"; } else { echo "<p>"; echo $content; echo " <a href='"; the_permalink(); echo "'>"."Read More →</a>"; echo "</p>"; } } ?>
How do I resolve my dilemma?
- The topic ‘Problems adding and removing sidebars.’ is closed to new replies.