Download - File Dropper

Transcript
114
Theme Options and Widgets
<?php
class Director_Featured_Widget extends WP_Widget {
public function __construct() {
// widget actual processes
}
public function form( $instance ) {
// outputs the options form on admin
}
public function update( $new_instance, $old_instance ) {
// processes widget options to be saved
}
public function widget( $args, $instance ) {
// outputs the content of the widget
}
}
register_widget( 'Director_Featured_Widget' );
?>
This is a slight modification of what we find in the WordPress
Codex.82 Let me explain each function quickly before we get any
farther.
First, we have a class called Director_Featured_Widget that
extends the built-in WordPress class WP_Widget(). This class has
four functions we can use when building our class:
1. _ _construct() – If you’re familiar with object-oriented
programming (OOP), you’ll know that this is the constructor.
This is essentially how we initialize our object. In this case,
we will define our widget using the constructor.
2. form() – If we are building widget options for the user to
customize the widget, we would do that here. We will be
using this only to change the title of the widget.
82 http://codex.wordpress.org/Widgets_API