ThemeShaper Forums » Thematic

[closed]

Make new Widget Area appear at top of admin page list

(7 posts)
  • Started 8 years ago by Solomon
  • Latest reply from Solomon
  • This topic is not resolved

Tags:

  1. I'm trying to get my widget area to appear at the top of the list of widget areas in the admin panel (the widgetized area in the template appears in the header after all). Here is the code I have in functions.php:

    function sol_headerbox_aside(){
    
    	register_sidebar(array(
    		'name' => 'Headerbox Aside',
    		'id' => 'headerbox-aside',
    		'description' => __('A widget area in the header for the contents of the large box on the right. You MUST keep a widget in here or the layout will break. Even a blank text widget is fine.', 'thematic'),
    		'before_widget' => thematic_before_widget(),
    		'after_widget' => thematic_after_widget(),
    		'before_title' => thematic_before_title(),
    		'after_title' => thematic_after_title(),)
    	);
    }
    add_action('init', 'sol_headerbox_aside');

    I know this has something to do with 'admin_menu_order' => 100, (lower than 100 actually)

    ...but I can't figure out where to place that. Little help?

    Posted 8 years ago #
  2. I believe there's two ways to register additional sidebar widgets, based on this post by helgaviking: http://forums.themeshaper.com/topic/header-widget-1#post-16111

    Does this get you there?

    function sol_headerbox_aside($content) {
            $content['Header Aside'] = array(
    			'admin_menu_order' => 91,
    			'args' => array (
    				'name' => 'Header Aside',
    				'id' => 'header-aside',
                    'description' => __('The header widget area.', 'thematic'),
    				'before_widget' => thematic_before_widget(),
    				'after_widget' => thematic_after_widget(),
    				'before_title' => thematic_before_title(),
    				'after_title' => thematic_after_title(),
    				),
    			'action_hook'	=> 'thematic_aboveheader',
    			'function'		=> 'thematic_header_aside',
    			'priority'		=> 10,
    			);
    
                  return $content;
    }
    
    add_filter('thematic_widgetized_areas', 'sol_headerbox_aside');
    
    // Define the Header Aside
    function thematic_header_aside() {
    	if (is_active_sidebar('header-aside')) {
    		echo thematic_before_widget_area('header-aside');
    		dynamic_sidebar('header-aside');
    		echo thematic_after_widget_area('header-aside');
    	}
    }
    Posted 8 years ago #
  3. the 'priority' is what controls where the widget areas stack up in the backend. you can take a look at which areas have which priority in the widget-extensions.php file

    Posted 8 years ago #
  4. Thank you both. Devin, I will give this a spin when I'm back in front of my development machine later and report back. Thank you for that effort.

    Helga, are you saying the 'admin_menu_order' bit doesn't matter? I see both in the widget-extensions.php file.

    Posted 8 years ago #
  5. Well, whatever the exact reason, it seems to work perfectly. Thank you both!

    Edit: OK, spoke a bit too soon. Here's what I have, and it does work, though I changed a little, and kept another function I had to add it to the page. It works as I show it here, but I've c/p'd so much at this point I've lost track at this point as to what everything does. I'm wondering if I've got something redundant going on here:

    function sol_headerbox_aside($content) {
            $content['Headerbox Aside'] = array(
    			'admin_menu_order' => 91,
    			'args' => array (
    				'name' => 'Headerbox Aside',
    				'id' => 'headerbox-aside',
                    'description' => __('A widget area in the header for the contents of the large box on the right. You MUST keep a widget in here or the layout will break. Even a blank text widget is fine.', 'thematic'),
    				'before_widget' => thematic_before_widget(),
    				'after_widget' => thematic_after_widget(),
    				'before_title' => thematic_before_title(),
    				'after_title' => thematic_after_title(),
    				),
    			'action_hook'	=> 'thematic_aboveheader',
    			'function'		=> 'thematic_header_aside',
    			'priority'		=> 10,
    			);
    
                  return $content;
    }
    
    add_filter('thematic_widgetized_areas', 'sol_headerbox_aside');
    
    // Define the Header Aside
    function thematic_header_aside() {
    	if (is_active_sidebar('header-aside')) {
    		echo thematic_before_widget_area('header-aside');
    		dynamic_sidebar('header-aside');
    		echo thematic_after_widget_area('header-aside');
    	}
    }
    
    // Add Header Box Sidebar Area on the Page
    function add_sol_headerbox_aside() {
      if (is_sidebar_active('headerbox-aside')) {
        echo thematic_before_widget_area('headerbox-aside');
        dynamic_sidebar('headerbox-aside');
        echo thematic_after_widget_area('headerbox-aside');
      }
    }
    add_action('thematic_header','add_sol_headerbox_aside', 10);

    I guess that last function add_sol_headerbox_aside() is for actually adding the contents of the widget area to the page. I'm getting confused with the is_active_sidebar and is_sidebar_active stuff. Sorry if this is obvious. My head is mushy at this point. :)

    Just want to confirm this is good code.

    Posted 8 years ago #
  6. sorry, you are right. the priority is for the priority of the function on its hook. admin menu order controls the order of things in the backend. <facepalm>.

    the function add_sol_headerbox_aside is redundant as far as i can tell (which isn't saying much after a bottle of vin rouge). the widget you've defined uses the thematic_header_aside() function so there is no need for the other one.

    does it work? devin's code ought to. i've used similar code myself many times.

    Posted 8 years ago #
  7. In the back end, yes, there's the widget box and widget in it, but without this part...

    // Add Header Box Sidebar Area on the Page
    function add_sol_headerbox_aside() {
      if (is_sidebar_active('headerbox-aside')) {
        echo thematic_before_widget_area('headerbox-aside');
        dynamic_sidebar('headerbox-aside');
        echo thematic_after_widget_area('headerbox-aside');
      }
    }
    add_action('thematic_header','add_sol_headerbox_aside', 10);

    ...it doesn't seem to hit the output page itself. Which is, I think, how it's supposed to be...?

    Without this:

    // Define the Header Aside
    function thematic_header_aside() {
    	if (is_active_sidebar('header-aside')) {
    		echo thematic_before_widget_area('header-aside');
    		dynamic_sidebar('header-aside');
    		echo thematic_after_widget_area('header-aside');
    	}
    }

    I get an error at the top of the (public) page.

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.