ThemeShaper Forums » Thematic

[closed]

How do I set the default widgets in my child theme?

(16 posts)
  • Started 8 years ago by helgatheviking
  • Latest reply from peterhol
  • This topic is resolved
  1. I'd like to specify which widgets go where in my child theme instead of using the default thematic setup.

    I tried this but no joy on my install. Still got those pesky meta and links widgets.

    $preset_widgets = array (
    	'primary-aside'  => array( 'CollisionWidget','search', 'categories'),
    	'secondary-aside'  => array( 'text' ),
    	'1st-subsidiary-aside'  => array( 'text' ),
    	'2nd-subsidiary-aside'  => array( 'text' ),
    	'3rd-subsidiary-aside'  => array( 'text' )
    
    );
    if ( isset( $_GET['activated'] ) ) {
    	update_option( 'sidebars_widgets', $preset_widgets );
    }
    Posted 8 years ago #
  2. Hi Helga,

    There is a filter for the preset widgets. Here's is how you're wanting to use it.

    function preset_child_widgets() {
    	$child_preset_widgets = array (
    		'primary-aside'  => array( 'search', 'categories'),
    		'secondary-aside'  => array( 'text' ),
    		'1st-subsidiary-aside'  => array( 'text' ),
    		'2nd-subsidiary-aside'  => array( 'text' ),
    		'3rd-subsidiary-aside'  => array( 'text' )
    
    	);
    return $child_preset_widgets;
    }
    add_filter('thematic_preset_widgets','preset_child_widgets' );

    Note this only works upon intial activation of your child theme so you'll have to switch themes to make any results show. Also I don't think this will reinstate pre-existing text widgets. It will only create new ones with no content in them until you add some.

    -Gene

    Posted 8 years ago #
  3. Well duh nothing happens if i don't filter/hook it in! <slaps forehead> thanks for this.

    Posted 8 years ago #
  4. lambeboy
    Member

    wordpress (2.9.2) - REALLY??? that's it? Wow! I have been struggling with this issue for a week now. Tried all the methods out there, including what helgatheviking tried. Was starting to think presetting widgets was not just a stable practice yet.

    even thought this new multi-widget implementation thingy had something to do with it:

    http://ptahdunbar.com/wordpress/round-2-preset-widgets-to-widget-areas/

    note-to-self: everything is a filter/hook

    Posted 8 years ago #
  5. Worked for me. Thanks Gene.

    Posted 8 years ago #
  6. I'm sorry - I still can't get this to work.. I copied the code by Gene into my functions.php (in a child theme) - but no widgets are showing when I reactivate the the theme!? (I tried changing back and forth using different themes, as well as activating widgets here and there.. but every time I reactivate the child theme, the widget areas are blank. I use WP 3.0-beta and Thematic 0.9.6.2)

    Posted 8 years ago #
  7. Activate the child theme with your filter of the $preset widgets array and then navigate to wp-admin>appearance>widgets At that point I believe you will see the new widgets appear on your site. Try it and let me know if this works albeit awkwardly.

    Posted 8 years ago #
  8. ok.. tried once more, and i got the code to work - kind of - so i think my problem might be of another kind. after seeing some thematic child themes i realized that whenever i use thematic, the only widget that is automatically registered, is the meta widget! so what i did now was basically to change your code to this:

    function preset_child_widgets() {
    	$child_preset_widgets = array (
    		'primary-aside'  => array( 'meta', 'meta'),
    		'secondary-aside'  => array( 'meta' ),
    		'1st-subsidiary-aside'  => array( 'meta' ),
    		'2nd-subsidiary-aside'  => array( 'meta' ),
    		'3rd-subsidiary-aside'  => array( 'meta' )
    
    	);
    return $child_preset_widgets;
    }
    add_filter('thematic_preset_widgets','preset_child_widgets' );

    and sure enough, the meta widget showed up three times in the sidebar, and three times in the footer..

    see http://holme.se/

    any idea what could be wrong? when I activate twenty-ten, both the search, archive and meta widgets are registered automatically.

    Posted 8 years ago #
  9. Comparing how Thematic to Twenty-ten or any other theme is like comparing apples to oranges. They're both likely using entirely different methods of registering sidebars and presetting widgets.

    What is the code you are using that does not work?

    Posted 8 years ago #
  10. well it's the same when I use the thematic "base theme" - only the meta widget shows (ie. no extra code)..

    Posted 8 years ago #
  11. It sounds like thmeatic's sidebars_widgets options array is fragged.

    Try reseting the widgets from the admin: wp-admin>appearance>thematic-options
    then activate your child theme and visit appearance>widgets in the admin and see if that helps

    Posted 8 years ago #
  12. have done that.. still only the meta widget is showing..

    Posted 8 years ago #
  13. got it: created a new site, and that worked, with all the plugins. I started looking for differences - and the only thing I found was that the new site was created using english - but the other site is using a norwegian translation.. so, when i changed the new sites language to norwegian - all the widgets disappeared (except for "meta") - and when i set the site to english again, the widgets showed!

    Posted 8 years ago #
  14. now.. what could be wrong with the translation files..?

    Posted 8 years ago #
  15. Seriously: I ran tests with both swedish and norwegian translation settings:

    Test 1
    1: wp-admin/options-general.php -> site language -> english
    2: change theme to twenty-ten
    3: go to wp-admin/widgets.php (no widgets are active)
    3: change theme back to thematic
    4: go to wp-admin/widgets.php
    Result: all widgets that are supposed to be there, are there (4 in primary aside, 3 in secondary aside). These widgets show up when going to the front page as well.

    Test 2
    1: wp-admin/options-general.php -> site language -> norwegian (or swedish)
    2: change theme to twenty-ten
    3: go to wp-admin/widgets.php (no widgets are active)
    3: change theme back to thematic
    4: go to wp-admin/widgets.php
    Result: only one widget is active ("meta", in secondary aside). This widget shows up when going to the front page as well.

    Posted 8 years ago #
  16. any thoughts on what could cause this behaviour?

    Posted 8 years ago #

RSS feed for this topic

Topic Closed

This topic has been closed to new replies.