Advertisement
MrPauloeN

Jak Wywołać Dowolny Widget Za Pomocą Skrótu (via ShortCode)?

May 14th, 2013
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.13 KB | None | 0 0
  1. // Call a Widget with a Shortcode
  2.  
  3.  
  4. function widget_via_shortcode_sc_pn($atts) {
  5.  
  6.     global $wp_widget_factory;
  7.  
  8.     extract(shortcode_atts(array(
  9.         'widget_name' => FALSE
  10.     ), $atts));
  11.  
  12.     $widget_name = wp_specialchars($widget_name);
  13.  
  14.     if (!is_a($wp_widget_factory->widgets[$widget_name], 'WP_Widget')):
  15.         $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
  16.  
  17.         if (!is_a($wp_widget_factory->widgets[$wp_class], 'WP_Widget')):
  18.             return '<p>'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'<strong>'.$class.'</strong>').'</p>';
  19.         else:
  20.             $class = $wp_class;
  21.         endif;
  22.     endif;
  23.  
  24.     ob_start();
  25.     the_widget($widget_name, $instance, array('widget_id'=>'arbitrary-instance-'.$id,
  26.         'before_widget' => '',
  27.         'after_widget' => '',
  28.         'before_title' => '',
  29.         'after_title' => ''
  30.     ));
  31.     $output = ob_get_contents();
  32.     ob_end_clean();
  33.     return $output;
  34.  
  35. }
  36.  
  37. // Remember to Call your shortcode through a unique name!!!
  38.  
  39. add_shortcode('widget-sc','widget_via_shortcode_sc_pn');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement