Hooking Into Widget Output Loop

Hook into ‘dynamic_sidebar’ and count how often it is called. You get the current active sidebar with key( $GLOBALS[‘wp_registered_sidebars’] ). add_action( ‘dynamic_sidebar’, ‘wpse_96681_hr’ ); function wpse_96681_hr( $widget ) { static $counter = 0; // right sidebar in Twenty Ten. Adjust to your needs. if ( ‘primary-widget-area’ !== key( $GLOBALS[‘wp_registered_sidebars’] ) ) return; if ( 0 … Read more

Transform php code into a widget?

Here is a stand-alone answer. Building a widget to echo hard-coded PHP is trivial. class PHP_Widget_wpse_80256 extends WP_Widget { function __construct() { $opts = array( ‘description’ => ‘Display Some Hard Coded PHP content’ ); parent::WP_Widget( ‘my-hc-php-content’, ‘Some PHP’, $opts ); } function widget($args,$instance) { // PHP goes here, like this: echo ‘PHP generated content’; } … Read more

Include custom post types in categories widget

I have an ‘actor’ cpt and it seems to automatically get added to the query: SELECT object_id, term_taxonomy_id FROM wp_term_relationships INNER JOIN wp_posts ON object_id = ID WHERE term_taxonomy_id IN (38,40,30,11,32,34,29,39,35,9,31,19,33,37,42,41,27,25,36,1,26) AND post_type IN (‘post’, ‘actor’) AND post_status=”publish” Call from: require, require_once, include, get_sidebar, get_template_part, locate_template, load_template, require, dynamic_sidebar, call_user_func_array, WP_Widget->display_callback, WP_Widget_Categories->widget, wp_list_categories, get_categories, get_terms, … Read more