Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Como crear widgets personalizados en el desarrollo de un tema en WordPress By Sergio Orozco

Como crear widgets personalizados en el desarrollo de un tema en WordPress By Sergio Orozco

WordPress Barranquilla

December 28, 2017
Tweet

More Decks by WordPress Barranquilla

Other Decks in Technology

Transcript

  1. ¿Alguna vez te has preguntado cómo funcionan esos fragmentos que

    se adicionan al footer u otros lugares del sitio? #WPBQ
  2. Código Base class My_Widget extends WP_Widget { // class constructor

    public function __construct() {} // output the widget content on the front-end public function widget( $args, $instance ) {} // output the option form field in admin Widgets screen public function form( $instance ) {} // save options public function update( $new_instance, $old_instance ) {} }
  3. Ejemplo hola mundo class Widget_Meetup1 extends WP_Widget { // class

    constructor public function __construct() { parent::__construct( 'meetup_widget1', // Base ID esc_html__( 'Widget Meetup 1', 'scot3004' ), // Name array( 'description' => esc_html__( 'Es un simple hola mundo', 'scot3004' ), ) // Args ); } // output the widget content on the front-end public function widget( $args, $instance ) { echo 'hola mundo'; } }
  4. Registrar Widgets function meetup_area_init() { register_sidebar( array( 'name' => __(

    'Meetup Area', 'twentyseventeen' ), 'id' => 'meetup_area', 'description' => __( 'Add widgets here to appear in your sidebar on blog posts and archive pages.', 'twentyseventeen' ), 'before_widget' => '<section id="%1$s" class="widget %2$s">', 'after_widget' => '</section>', ) ); } add_action( 'widgets_init', function(){ meetup_area_init(); register_widget( 'Widget_Meetup1' ); register_widget( 'Widget_Meetup2' ); });