This is how I set default widgets:
<div class="sidebar">
<?php
if ( !dynamic_sidebar('right-sidebar') ) :
if (is_cp_theme_layout('standard,v')) {
the_widget('comicpress_calendar_widget');
}
if (comicpress_themeinfo('disable_comic_frontpage')) {
the_widget('comicpress_latest_thumbnail_widget','title=Latest Comic&thumbcat='.comicpress_themeinfo('comiccat'));
}
the_widget('WP_Widget_Pages');
the_widget('WP_Widget_Categories','hierarchical=1&count=1&dropdown=0');
endif;
?>
</div>
Basically, if the end user didn’t add widgets to the sidebar it will use those defaults i setup, allowing it to not be empty when someone activated the theme.
The key thing your looking for is the function called the_widget http://codex.wordpress.org/Function_Reference/the_widget
Thread Starter
czone
(@czone)
Thanks Frumph for helping me, your suggestion solved my prob.
BUT 1 PROBLEM
What if I am using a widget which is not installed in WordPress by default?
Since the default widget for search do not allow any styles CSS so I used “Customizable Search Widget” for that. How to embed that?
notice the_widget(‘comicpress_calendar_widget’)
that’s not a default widget, it’s one of my theme created ones
If you are properly creating your widgets per the 2.8+ widget code, you use I believe the registered name for the widget, which in my case I do this:
class comicpress_calendar_widget extends WP_Widget {
function comicpress_calendar_widget($skip_widget_init = false) {
if (!$skip_widget_init) {
$widget_ops = array('classname' => __CLASS__, 'description' => __('Display a calendar showing this months posts. (this calendar does not drop lines if there is no title given.)','comicpress') );
$this->WP_Widget(__CLASS__, __('Comic Calendar','comicpress'), $widget_ops);
}
}
the __CLASS__ is the classname itself so when registering the WP_Widget it basically keeps the same class name there.
Which the classname is then used as the_widget(‘thatnameregistered’)