Why is registering a sidebar for each page causing my sidebars to reset?

You need to wrap this in a function then add it to the widgets_init action. Also the register sidebar function does not have $arguments for sort_column or sort_order. I would also change the id to ‘sidebar-‘.$page->ID add_action( ‘widgets_init’, ‘prefix_register_sidebars’ ); function prefix_register_sidebars() { foreach($pages as $page){ register_sidebar( array( ‘name’=>$page->post_title, ‘id’=> ‘sidebar-‘.$page->ID, ‘before_widget’ => ‘<div id=”%1$s” … Read more

Upgraded to 3.3, My Widgets Disappeared

Check if your theme is compatible with WP 3.3. To check, you may try switching to the default theme (twentyeleven) for a moment by renaming your current theme’s folder in wp-content/themes. The idea is to force WordPress to fall back to the default theme to rule out any theme-specific issue. -also, make sure all your … Read more

How to customize wordpress sidebar widget

register_sidebar(array( ‘name’ => ‘Post Sidebar’, ‘before_widget’ => ‘<div id=”%1$s” class=”widget %2$s”>’, ‘after_widget’ => ‘</div></div>’, ‘before_title’ => ‘<div class=”titlediv”>’, ‘after_title’ => ‘</div><div class=”widgetdiv”>’, )); You will have a wrapper div, then your title div and then your widgetdiv.

Adding dashboard widgets to show – custom post type stats, information from other plugins

You can get a little more fancy, but this should get you started. add_action( ‘right_now_content_table_end’, ‘wpse_3809’); function wpse_3809() { $types = get_post_types( array( ‘_builtin’ => false ) ); foreach( $types as $type ) : $num_posts = wp_count_posts( $type ); $num = number_format_i18n( $num_posts->publish ); ?> <tr> <td class=”first b b_<?php echo $type; ?>”> <a href=”https://wordpress.stackexchange.com/questions/38098/edit.php?post_type=<?php … Read more

How to exclude categories from get_categories() select list inside a widget admin panel

Per http://codex.wordpress.org/Class_Reference/WP_Query you would need to prefix the numerical identifier of the array with a minus-sign, such as $query = new WP_Query( ‘cat=-12,-34,-56’ );, which would exclude the categories with the identifier 12, 34 and 56. You could achieve this by changing the get_cats function into the following: function get_cats(){ $exclude_cats = array( get_cat_ID(‘test1’), get_cat_ID(‘test2’), … Read more

Don’t display a sidebar widget when on a specific page

Assuming that the ‘blog’ slug is correct, your code would work. I would suggest making a separate template for the page, namely page-blog.php (see http://codex.wordpress.org/images/1/18/Template_Hierarchy.png and http://codex.wordpress.org/Template_Hierarchy) where you set up the structure and appearance of the page exactly as you want it to be. WordPress will automatically look for the file when opening a … Read more

Distinguish between different widgets of the same type

The correct practice is actually to use $args[‘before_widget] and $args[‘after_widget’] to handle the id, class, and anything else. In pseudo code: class My_Widget extends WP_Widget { function My_Widget() { //basic widget settings. $widget_ops = array( ‘classname’ => ‘my-name’, ‘description’ => ‘This is the description’ ); //widget control settings. $control_ops = array( ‘id_base’ => ‘my-name-widget’ ); … Read more