Articles of widgets

how to extend a WP_widget twice

Has someone ever tried to extend calss WP_Widget, then extend it again ? Having to related widgets, I tried to create the first extending WP_Widget, : class FirstWidget extends WP_Widget { public function __construct(){ parent::__construct( etc and then extending the First to create the second one : class SecondWidget extends FirstWidget { public function __construct(){ […]

Widget Option is Missing

My Widget Option is missing in the Dashboard area. How can i make that appear? I have downloaded this Blank Theme from Chris Coyiers site. sidebar.php <?php /** * @package WordPress * @subpackage HTML5-Reset-WordPress-Theme * @since HTML5 Reset 2.0 */ ?> <div class=”sidebar”> <?php if (!function_exists(‘dynamic_sidebar’) && !dynamic_sidebar(‘Sidebar Widgets’)) : else : ?> <!– All […]

Count widgets in position and set class

(Please be gentle, I’m transitioning from Joomla development.) I am using Twitter Bootstrap for this client and I would like the “bottom” widget position to work “automatically” for my client as I am used to in Joomla where if there are 2 modules published in a position, then the appropriate classes will be added on […]

disbale default widgets on theme activation

I want to deactivate all default widgets on theme activation which are active by default for new WordPress installation. I’m using following function as callback for theme activation : if ( is_admin() && isset($_GET[‘activated’] ) && $pagenow == ‘themes.php’ ) { // } By default activated widgets are : Search Recent Posts Recent Comments Archives […]

How to use get_results() in widget front end?

I’m trying to get_results() in my widget’s front end, this is my current code: public function widget( $args, $instance ) { echo $args[‘before_widget’]; if($children = $wpdb->get_results( “SELECT ID FROM $wpdb->posts” )) echo “working”; echo $args[‘after_widget’]; } However I’m getting error “Fatal error: Call to a member function get_results() on a non-object”. I need to access […]

How to best include widget area just on homepage?

I have a front-page.php defining the homepage of my theme (a Genesis child theme). In it, I have some custom widget areas, like so: genesis_register_sidebar( array( ‘id’ => ‘cta’, ‘name’ => __( ‘How do I Connect?’, ‘site’ ), ‘description’ => __( ‘This is the cta widget for the home page.’, ‘site’ ), ) ); add_action( […]

Customizing the Widget content markup

I am using bootstrap to create panels for the sidebar widgets, and I can set the container markup for the widget, as well as the markup for the panel header, but I cannot provide the markup for the panel content. I have this so far: register_sidebar(array( ‘name’ => __(‘Right Sidebar’), ‘id’ => ‘home_right_1’, ‘before_widget’ => […]

wp_dropdown_pages in widget form

I have a small quirk somewhere in my widget form. Upon saving the widget instance, the form refreshes with the wrong selected ‘page_id’ from the wp_dropdown_pages input. If I refresh the widgets page, the correct, saved page_id is selected in the dropdown. Here’s the portion of code: public function form( $instance ) { if( isset( […]

Add Shortcode tag in Widget/Sidebar

I want to add a shortcode tag in the sidebar/widget. I am able to get the required functionality if I add the code in the theme’s function.php add_filter(‘widget_text’, ‘do_shortcode’); My problem is that I am searching for a way I can do this from the plugins files itself without affecting any of the theme files. […]

How to include a file only on dashboard widgets page?

I want to add some styles to the widgets input fields. Therefore I want to include a style.css file only on the wp-admin/widgets.php page. How can I detect the above page and include file there?