Count widgets in position and set class

I found an answer on this very site that didn’t come up before in search before @ Get number of widgets in sidebar function cosmos_bottom_sidebar_params($params) { $sidebar_id = $params[0][‘id’]; if ( $sidebar_id == ‘sidebar-bottom’ ) { $total_widgets = wp_get_sidebars_widgets(); $sidebar_widgets = count($total_widgets[$sidebar_id]); $params[0][‘before_widget’] = str_replace(‘class=”‘, ‘class=”span’ . floor(12 / $sidebar_widgets) . ‘ ‘, $params[0][‘before_widget’]); } … Read more

how to extend a WP_widget twice

You have to make sure that all of your parameters are passed all the way through to the WP_Widget class. Your code is very truncated but I am pretty sure that is what you are doing wrong. The widget code below works– it doesn’t do much of anything, but it works. See if you can … Read more

Multiple entries in get_option results? or why is _multiwidget set to 1?

I found the answer. Multiwidget is a nice new feature within wordpress’ new widget API. Yet there is sparse documentation on how to use it. $options = get_option( ‘your_option_id’ ); if( isset($options) && isset($options[$this->number])) { //$this->number returns the unique widget id that corresponds to the database index $instance_options = $options[$this->number]; } //now use $instance_options[‘setting’]

Widget Area: Modify $param[‘xy’] from widget-$n

The dynamic_sidebar_params filter is called before each widget is displayed, so multiple times in the same sidebar. It filters the $args and $instance parameters that will be passed to the widget. If you only want to execute it for the third widget of a specific sidebar, you should check for the sidebar ID (found in … Read more

How to check if widget has automatic title

Any widgets written to operate as the Core “Recent Posts” widget does can be forced to skip the title by a filter on widget_title: function widget_title_hack_191120($title, $instance) { if (empty($instance[‘title’])) { $title=””; } return $title; } add_filter(‘widget_title’,’widget_title_hack_191120′, 10, 2); I don’t know if there is a generic solution to the problem. Any widget could avoid … Read more

Enabling Default Widgets in a Custom Theme

that’s not the way, wp_register_sidebar_widget is used to create widgets. if you want your sidebar to display widgets by default use [dynamic_sidebar()][1] in your theme eg from the 2010 theme: <div id=”primary” class=”widget-area” role=”complementary”> <ul class=”xoxo”> <?php /* When we call the dynamic_sidebar() function, it’ll spit out * the widgets for that widget area. If … Read more

How to add the widgets manually to the sidebar?

Have a look at the the_widget() function. The first argument is required. It is the PHP class name of the widget. For example: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Search’) ?> </div> You can also pass on extra arguments: <div class=”sidebar”> <?php the_widget(‘WP_Widget_Text’, ‘title=Hello&text=World’) ?> </div>

Need help adding additional controls to a custom widget Part 2

Here is an updated version of the widget which handles the vertical layout option, including categories, and excluding categories. Handling the vertical layout option is pretty straightforward; we just check to see if the option is checked, and if so, output the appropriate classes. Handling the inclusion/exclusion of categories is a little more complex because … Read more