How do I display the “Archives” widget layout (sidebar) in WordPress by ‘year’ then by ‘months’?

Changing the default widget would be pretty complicated. However, you can write your own shortcode and function to get your desired list. I’m guessing you want an unordered list in your widget? Put this in your theme’s functions.php: add_shortcode(‘archive_by_year_and_month’,’get_archive_by_year_and_month’); function get_archive_by_year_and_month($atts=array()){ global $wpdb; $years = $wpdb->get_col(“SELECT DISTINCT YEAR(post_date) FROM $wpdb->posts WHERE post_type=”post” AND post_status=”publish” ORDER … Read more

WordPress multiple widget in single plugin

There is absolutely no problem with registering several widgets inside one file. Widgets are separate classes, and unlike other programming languages, PHP will have no problem with your declaring two classes inside one file. add_action( ‘widgets_init’, ‘src_load_widgets’ ); function src_load_widgets() { register_widget( ‘Widget_SRC’ ); register_widget( ‘Widget_Rank ‘ ); } class Widget_SRC extends WP_Widget { // … Read more

How can I add a new CSS class to a widget?

Don’t edit your parent theme’s functions.php file. register_sidebar( array( ‘name’ => __( ‘Sidebar name’, ‘theme_text_domain’ ), ‘id’ => ‘unique-sidebar-id’, ‘description’ => ”, ‘class’ => ‘add class here’, ‘before_widget’ => ‘<li id=”%1$s” class=”widget %2$s”>’, ‘after_widget’ => ‘</li>’, ‘before_title’ => ‘<h2 class=”widgettitle”>’, ‘after_title’ => ‘</h2>’ ) ); Copy it over to your child theme’s functions.php and make … Read more

Unable to save widget contents

Reason is pretty simple and easy to overlook… It has nothing to do with placing both widgets in the same file or anything like this… Let’s look at your code that is responsible for printing the widgets’ form: public function form( $instance ) { echo ‘<p><strong>Sometext here</p>’; } Do you see it now? There are … Read more

How to add multiple custom widget areas

You have to register multiple areas: function new_sidebar_widget_init() { register_sidebar( array( ‘name’ => ‘new-sidebar’, ‘id’ => ‘new-sidebar’, ‘before_widget’ => ‘<div id=”new-sidebar”>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ”, ‘after_title’ => ”, ) ); register_sidebar( array( ‘name’ => ‘new-sidebar-1’, ‘id’ => ‘new-sidebar-1’, ‘before_widget’ => ‘<div id=”new-sidebar”>’, ‘after_widget’ => ‘</div>’, ‘before_title’ => ”, ‘after_title’ => ”, ) ); … Read more

Categories lose hierarchy order once assigned to post

You could try out Scribu’s plugin, i believe this addresses the very problem you’re describing which has been reported on Trac a handful of times(but closed/deleted). Category Checklist Tree by scribu http://wordpress.org/extend/plugins/category-checklist-tree/ Related tickets: http://core.trac.wordpress.org/ticket/14723 http://core.trac.wordpress.org/ticket/10982 Hope that helps.. 🙂

Get all posts by post_author

The shortest possible answer would be to correct ‘post_author’ to ‘author’, since that is the key WP is looking for. If a key is incorrect or misspelled it will be ignored, as was the case with ‘post_author’.

How do I pass arguments to dashboard widget callback functions?

The args are stored in the 2nd variable passed to your callback function. add_action( ‘wp_dashboard_setup’, ‘sample_widget_setup’ ); function sample_widget_setup() { wp_add_dashboard_widget( ‘sample_dashboard_widget’, ‘Sample Widget’, ‘sample_dashboard_widget_callback’, null, ‘sample_string’ ); } function sample_dashboard_widget_callback( $var, $args ) { var_dump( $args ); } Output from above: array ‘id’ => string ‘sample_dashboard_widget’ (length=23) ‘title’ => string ‘Sample Widget’ (length=13) ‘callback’ … Read more

How to add a description to Widgets?

Here’s what you looking for: class WP_Widget_Sitemap extends WP_Widget { function WP_Widget_Sitemap() { $widget_ops = array( ‘classname’ => ‘widget_sitemap’, ‘description’ => __( “This is the description” ) ); $this->WP_Widget( ‘sitemap’, __(‘Site Map’), $widget_ops); } function widget() { … } function form() { … } function update() { … } … See: http://codex.wordpress.org/Widgets_API#Developing_Widgets