Context aware widgets. My work in progress

Just like you would from a widget() method: function wse_widget_display_callback($instance) { $show_it = true; if(isset($instance[‘noHome’]) && $instance[‘noHome’] && is_home()) $show_it = false; if(isset($instance[‘noPages’]) && $instance[‘noPages’] && is_page()) $show_it = false; … if($show_it) return $instance; else return false; } I’ve posted here the functions I use to accomplish this, it might be helpful. The form hooks … Read more

Using tabs in admin widgets [closed]

The problem is that you’re not using unique IDs (#tabs, #tabs-1 …), because widgets have multiple instances (the same IDs are used by the instance form the “Available Widgets” area). So just prepend or append the widget instance ID to your identifiers to make them unique: … <div id=”tabs-<?php echo $this->id; ?>”> <ul> <li><a href=”#tabs-<?php … Read more

How do I create a drop down menu in a widget?

This is what I do: Static Options <select id=”<?php echo $this->get_field_id(‘posttype’); ?>” name=”<?php echo $this->get_field_name(‘posttype’); ?>” class=”widefat” style=”width:100%;”> <option <?php selected( $instance[‘posttype’], ‘Option 1’); ?> value=”Option 1″>Option 1</option> <option <?php selected( $instance[‘posttype’], ‘Option 2’); ?> value=”Option 2″>Option 2</option> <option <?php selected( $instance[‘posttype’], ‘Option 3’); ?> value=”Option 3″>Option 3</option> </select> Generate with options with PHP (example) … Read more

Including a custom post type in the Archives widget

The Archive widget is using wp_get_archives() to display the archive. If you want to target all the wp_get_archives() functions, you can use the getarchives_where filter to add your custom post type: add_filter( ‘getarchives_where’, ‘custom_getarchives_where’ ); function custom_getarchives_where( $where ){ $where = str_replace( “post_type=”post””, “post_type IN ( ‘post’, ‘videos’ )”, $where ); return $where; } If … Read more

modify a output of a widget

I would copy the widget from the core as needed, put it in the theme or plugin, but you should also unregister the core widget you are replacing. That can be done like this: // unregister all default WP Widgets function unregister_default_wp_widgets() { unregister_widget(‘WP_Widget_Pages’); unregister_widget(‘WP_Widget_Calendar’); unregister_widget(‘WP_Widget_Archives’); unregister_widget(‘WP_Widget_Links’); unregister_widget(‘WP_Widget_Meta’); unregister_widget(‘WP_Widget_Search’); unregister_widget(‘WP_Widget_Text’); unregister_widget(‘WP_Widget_Categories’); unregister_widget(‘WP_Widget_Recent_Posts’); unregister_widget(‘WP_Widget_Recent_Comments’); unregister_widget(‘WP_Widget_RSS’); unregister_widget(‘WP_Widget_Tag_Cloud’); … Read more

How to execute SQL SELECT query and see the results?

Have a look at the $wpdb class, it does exactly what you want: $myrows = $wpdb->get_results( “SELECT id, name FROM mytable” ); Try to avoid SQL queries for basic operations though. WordPress offers you many convenience functions for 80% of the tasks you would every come up with. They provide a nicer interface and preserve … Read more

Different rss feeds in a single dashboard widget

Yes, @toscho is right, the url works with an array of feeds adresses. And if you have 5/6 feeds, the total of items should be 20/24. For clear separation, I think it’s better to run the wp_widget_rss_output function n number of times, and prepare a previous array with titles and addresses and iterate through it. … Read more

Big side banners

Register sidebars for the banners, then use the text widget to place your code in it. The default widget will strip some HTML code, so you may want to use something less invasive like my Unfiltered Text Widget.

Call sidebar from a template

Impossible with get_sidebar(). From that function’s body: function get_sidebar( $name = null ) { do_action( ‘get_sidebar’, $name ); $templates = array(); if ( isset($name) ) $templates[] = “sidebar-{$name}.php”; $templates[] = ‘sidebar.php’; So if you pass a $name or any other custom value to the function, they will be set between two fixed strings. You can … Read more