ThemeShaper Forums » Thematic

[closed]

how to add widget areas

(12 posts)
  • Started 10 years ago by blackinches
  • Latest reply from flick
  • This topic is resolved

Tags:

  1. blackinches
    Member

    how do i add another widget area? basically another area like the primary or secondary widget area.

    Posted 10 years ago #
  2. amygail
    Member

    This should help

    http://forums.themeshaper.com/topic/widgets-in-the-header

    Posted 10 years ago #
  3. Hi,

    if you could wait until Friday .. I'm working on a functionality that enables you to create a widget area with a single line :)

    It's already working on my local machine for the regular sidebar. I need to rewrite Thematic to use this code for all other widget areas, add some more bells & whistles, do some testing and write a tiny bit of documentation for it.

    Chris

    Posted 10 years ago #
  4. Chris, did you ever come out with that one-line-function to add widget areas?

    I want to add a widgetizable area on the thematic_abovefooter() hook...

    Thanks in advanced!

    Theo

    Posted 9 years ago #
  5. I came up with one of your posts and wrote this:

    // This will create your widget area
    function my_widgets_init() {
        register_sidebar(array(
           	'name' => 'Above Footer Aside',
           	'id' => 'above-footer-aside',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => '</li>',
    		'before_title' => "<h3 class=\"widgettitle\">",
    		'after_title' => "</h3>\n",
        ));
    
    }
    add_action( 'init', 'my_widgets_init' );
    
    // adding the widget area to your child theme
    function above_footer_widgets() {
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('above-footer-aside') ) {
        echo '<div id="above-footer-aside" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
        dynamic_sidebar('above-footer-aside');
        echo '</ul>' . "\n" . '</div><!-- #above-footer-aside .aside -->'. "\n";
    }
    }
    add_action('thematic_abovefooter', 'above_footer_widgets', 8);

    Is this the best way to go or is there really a one line function =)

    Thanks!

    Posted 9 years ago #
  6. Hi Theo,

    tried this a while ago. I created a one-line version which was able to handle only one widgetized area inside of an action hook. As soon as you want to implement a second or third widgetized area you need to write an additional function. So I dropped this code.

    I'm working on a new code that makes it easier to create a real flexible widgetized area. It won't be a one-line solution. The code is similar to the one above.

    This is an example for creating an additional special Secondary Aside that will dispay on pages:

    function change_secondary_aside($content) {
            // change the standard function for Secondary Aside to our new one
    	$content['Secondary Aside']['function'] = 'childtheme_secondary_aside';
            // create the new widgetized area
    	$content['Secondary Aside Pages'] = array(
                    // this is used to sort the list of widgetized areas in wp-admin
    		'admin_menu_order' => 201,
                    // defines our needed arguments .. btw. you can filter the markup
    		'args' => array (
    			'name' => 'Secondary Aside Pages',
    			'id' => 'secondary-aside-pages',
    			'before_widget' => thematic_before_widget(),
    			'after_widget' => thematic_after_widget(),
    			'before_title' => thematic_before_title(),
    			'after_title' => thematic_after_title(),
    		),
                    // that's the action hook where we integrate the widgetized area
    		'action_hook'	=> 'thematic_secondary_aside',
                    // the function that defines the wigetized area
    		'function'		=> 'childtheme_secondary_aside',
                    // ... and the priority of this function
    		'priority'		=> 10,
    	);
    
    	return $content;
    }
    add_filter('thematic_widgetized_areas','change_secondary_aside');
    
    function childtheme_secondary_aside() {
            // we start to display if both areas have widgets
    	if (is_sidebar_active('secondary-aside') && is_sidebar_active('secondary-aside-pages')) {
    		echo thematic_before_widget_area('secondary-aside');
    		if (is_page()) {
                            // this is a page and we dispay our special Secondary Aside
    			dynamic_sidebar('secondary-aside-pages');
    		} else {
                            // this isn't a page and we display our regular Secondary Aside
    			dynamic_sidebar('secondary-aside');
    		}
    		echo thematic_after_widget_area('secondary-aside');
    	}
    }

    Need to do some minor changes / additions:
    - embed the sort into a filter function, just in case that someone wants to change it to anything else
    - change the sidebar code for the footer
    - a bit house keeping

    Chris

    Posted 9 years ago #
  7. That looks great!

    The one I wrote above is working nice for above the footer though, I'm thinking if I want 1 widget aside area or 3 above the footer...

    Thank you so much again Chris. Thematic is awesome and the support you provide is unsurpassed! If you happen to refine the function it would be nice to have it on you code snippets page!

    Posted 9 years ago #
  8. Will do that .. and there will be something new latest 'til end of this year :)

    Posted 9 years ago #
  9. Chris, I don't want to bother by asking so much =) but though I'm studying some PHP it's a whole new universe for me (I'm a photographer).

    I decided I need 3 widget areas on the thematic_abovefooter() and I read the function you proposed but couldn't really figure out how to do it. I could of course repeat the function I wrote 3 times to get 3 areas but that is probably overkill.

    I might use some help...

    Posted 9 years ago #
  10. Hi Theo,

    :) .. and a good one!

    No .. my_windets_init() would contain 3 x the register_sidebar() function (one for each widgetized area) and you would do the same with above_footer_widgets(). This function would contain 3 x the current content (again one for each widgetized area).

    Chris

    Posted 9 years ago #
  11. Thanks for the advice Chris,

    For the record, I will display the functions I wrote in case anyone is looking for something similar. Here I'm creating 3 new widget areas, creating an action hook to put them inside the thematic_abovefooter() and then actually putting them on the newly created action hook.

    If anyone has tips to improve that coding they are very welcome but this works otherwise and I can create new widget areas easily to put somewhere else...

    <?php
    // Register my widget Areas
    function my_widgets_init() {
    	if ( !function_exists('register_sidebars') )
    		return;
    	  // Register Widgetized areas.
    			   // Area 1
                register_sidebar(array(
           	'name' => 'Above Footer Aside 1',
           	'id' => 'above-footer-aside-1',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => '</li>',
    		    'before_title' => "<h3 class=\"widgettitle\">",
    		    'after_title' => "</h3>\n",
        ));
    				// Area 2
                register_sidebar(array(
           	'name' => 'Above Footer Aside 2',
           	'id' => 'above-footer-aside-2',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => '</li>',
    		    'before_title' => "<h3 class=\"widgettitle\">",
    		    'after_title' => "</h3>\n",
        ));
    			  // Area 3
                register_sidebar(array(
           	'name' => 'Above Footer Aside 3',
           	'id' => 'above-footer-aside-3',
           	'before_widget' => '<li id="%1$s" class="widgetcontainer %2$s">',
           	'after_widget' => '</li>',
    		    'before_title' => "<h3 class=\"widgettitle\">",
    		    'after_title' => "</h3>\n",
        ));
    }
    add_action( 'init', 'my_widgets_init' );
    
    // Creates the Above footer Widgets Action Hook
    function above_footer_widgets() {
        do_action('above_footer_widgets');
    } // end thematic_abovefooter
    
    // Creates the above footer widgets container
    function above_footer_widgets_container() {
          // adds the container div to the widgets
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('above-footer-aside-1') OR is_sidebar_active('above-footer-aside-2') OR is_sidebar_active('above-footer-aside-3') ) {
        //opens the container
        echo '<div id="thematic-above-footer">' . "\n" . '<div id="thematic-above-footer-widgets">' . "\n";
        // calls the widgets
        above_footer_widgets ();
        //closes the container
        echo '</div><!-- thematic-above-footer-widgets -->' . "\n" . '</div><!-- thematic-above-footer -->' . "\n"  ;
    }
    }
    add_action('thematic_abovefooter', 'above_footer_widgets_container');
    
    // adds  widget areas to the thematic_abovefooter hook
    function insert_above_footer_widgets() {
          // Area 1
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('above-footer-aside-1') ) {
        echo '<div id="above-footer-aside-1" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
        dynamic_sidebar('above-footer-aside-1');
        echo "\n" . '</ul>' . "\n" . '</div><!-- #above-footer-aside-1 .aside -->'. "\n";
    }
          // Area 2
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('above-footer-aside-2') ) {
        echo '<div id="above-footer-aside-2" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
        dynamic_sidebar('above-footer-aside-2');
        echo "\n" . '</ul>' . "\n" . '</div><!-- #above-footer-aside-2 .aside -->'. "\n";
    }
          // Area 3
    if ( function_exists('dynamic_sidebar') && is_sidebar_active('above-footer-aside-3') ) {
        echo '<div id="above-footer-aside-3" class="aside">'. "\n" . '<ul class="xoxo">' . "\n";
        dynamic_sidebar('above-footer-aside-3');
        echo "\n" . '</ul>' . "\n" . '</div><!-- #above-footer-aside-3 .aside -->'. "\n";
    }
    }
    add_action('above_footer_widgets', 'insert_above_footer_widgets');
    ?>
    Posted 9 years ago #
  12. I'm sure this function has been introduced already, but unfortunately I'm being very blind here.

    Say for instance, if I wanted to add a 4th Subsidiary widget that spanned across the bottom of 1st and 2nd Subsidiary aside?

    Or would this be more of a css styling issue?

    Thanks. :)

    Posted 9 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.