daniofilho
4/12/2016 - 11:42 AM

criar widget

class Wid_lorem_Categorias extends WP_Widget {
	
		function __construct() {
			parent::__construct(
			// widget ID
			'Wid_lorem_Categorias',//'wpb_widget', 
			
			// Nome do Widgets na UI
			__('lorem Widget - Categorias', 'Wid_lorem_Categorias_domain'), 
			
			// Descrição
			array( 'description' => __( 'Exibe as Categorias de Posts cadastradas.', 'Wid_lorem_Categorias_domain' ), ) 
			);
		}
	
		// Front End
		public function widget( $args, $instance ) {
			$title = apply_filters( 'widget_title', $instance['title'] );
			// before and after widget arguments are defined by themes
			echo $args['before_widget'];
			if ( ! empty( $title ) )
			echo $args['before_title'] . $title . $args['after_title'];
			
			// Toda a funcionalidade do Widget entra aqui
			echo __( 'Hello, World!', 'Wid_lorem_Categorias_domain' );
			
			
			
			echo $args['after_widget'];
		}
				
		// Back End 
		public function form( $instance ) {
			
			if ( isset( $instance[ 'title' ] ) ) {
					$title = $instance[ 'title' ];
			} else {
				$title = __( 'Categorias', 'Wid_lorem_Categorias_domain' );
			}
		
		// Widget admin form
		?>
		<p>
			<label for="<?php echo $this->get_field_id( 'title' ); ?>"><?php _e( 'Title:' ); ?></label> 
			<input class="widefat" id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" type="text" value="<?php echo esc_attr( $title ); ?>" />
		</p>
		<?php 
		}
		
		// Atualização das instâncias do Widget
		public function update( $new_instance, $old_instance ) {
			$instance = array();
			$instance['title'] = ( ! empty( $new_instance['title'] ) ) ? strip_tags( $new_instance['title'] ) : '';
			return $instance;
		}
	} // Wid_lorem_Categorias
	
	// Registra e carrega o Widget
	function wpb_load_widget() {
		register_widget( 'Wid_lorem_Categorias' );
	}
	add_action( 'widgets_init', 'wpb_load_widget' );