pietergoosen

widgets.php

Jan 13th, 2014
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. $dynamic_widget_areas = array (
  2. 'sidebar-21' => __( 'Page Specific Sidebar 1', 'pietergoosen' ),
  3. 'sidebar-22' => __( 'Page Specific Sidebar 2', 'pietergoosen' ),
  4. 'sidebar-23' => __( 'Page Specific Sidebar 3', 'pietergoosen' ),
  5. 'sidebar-24' => __( 'Page Specific Sidebar 4', 'pietergoosen' ),
  6. 'sidebar-25' => __( 'Page Specific Sidebar 5', 'pietergoosen' ),
  7. 'sidebar-26' => __( 'Page Specific Sidebar 6', 'pietergoosen' ),
  8. 'sidebar-27' => __( 'Page Specific Sidebar 7', 'pietergoosen' ),
  9. 'sidebar-28' => __( 'Page Specific Sidebar 8', 'pietergoosen' ),
  10. 'sidebar-29' => __( 'Page Specific Sidebar 9', 'pietergoosen' ),
  11. 'sidebar-30' => __( 'Page Specific Sidebar 10', 'pietergoosen' ),
  12. );
  13.  
  14. foreach ( $dynamic_widget_areas as $id => $dynamic_widget_area ) {
  15. register_sidebar(
  16. array (
  17. 'name' => __( $dynamic_widget_area, 'pietergoosen' ),
  18. 'id' => $id,
  19. 'description' => __( 'Page specific sidebars above the content sidebar', 'pietergoosen' ),
  20. 'before_widget' => '<aside id="%1$s" class="widget %2$s">',
  21. 'after_widget' => '</aside>',
  22. 'before_title' => '<h1 class="widget-title">',
  23. 'after_title' => '</h1>',
  24. ));
  25. }
  26. }
  27. add_action( 'widgets_init', 'pietergoosen_widgets_init' );
  28.  
  29. // Add dynamic sidebars
  30. add_action('admin_init', 'sidebar_init');
  31. add_action('save_post', 'save_sidebar_link');
  32. function sidebar_init(){
  33. add_meta_box("sidebar_meta", "Sidebar options", "sidebar_link", "page", "side", "default");
  34. }
  35. function sidebar_link(){
  36. global $post, $dynamic_widget_areas;
  37. $custom = get_post_custom($post->ID);
  38. $link = $custom["_sidebar"][0];
  39. ?>
  40. <div class="link_header">
  41. <?
  42. echo '<select name="link" class="sidebar-selection">';
  43. echo '<option>Choose Sidebar</option>';
  44. echo '<option>No sidebars to choose from</option>';
  45. foreach ( $dynamic_widget_areas as $list ){
  46. if($link == $list){
  47. echo '<option value="'.$list.'" selected="true">'.$list.'</option>';
  48. }else{
  49. echo '<option value="'.$list.'">'.$list.'</option>';
  50. }
  51. }
  52. echo '</select><br />';
  53. ?>
  54. </div>
  55. <p>Choose the sidebar to use with this page.</p>
  56. <?php
  57. }
  58. function save_sidebar_link(){
  59. global $post;
  60. if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {return $post->ID;}
  61. update_post_meta($post->ID, "_sidebar", $_POST["link"]);
  62. }
  63. add_action('admin_head', 'sidebar_css');
  64. function sidebar_css() {
  65. echo'
  66. <style type="text/css">
  67. .sidebar-selection{width:100%;}
  68. </style>
  69. ';
  70. }
Advertisement
Add Comment
Please, Sign In to add comment