Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action('widgets_init', 'campus_html');
- function campus_html() { // function name matches name from add_action
- register_widget('Campus_HTML');
- }
- class Campus_HTML extends WP_Widget {
- function Campus_HTML() { // function name matches class name
- $widget_ops = array(
- 'classname'=>'campus-html-widget', // class that will be added to li element in widgeted area ul
- 'description'=>'Campus HTML Widget' // description displayed in admin
- );
- $control_ops = array(
- 'width'=>200, 'height'=>250, // width of input widget in admin
- 'id_base'=>'campus-html-widget' // base of id of li element ex. id="example-widget-1"
- );
- $this->WP_Widget('campus-html-widget', 'Campus HTML', $widget_ops, $control_ops); // "Example Widget" will be name in control panel
- }
- function widget($args, $instance) {
- extract($args);
- // these are our widget options
- $output = $before_widget;
- // how input text will be displayed
- $output .= '<img class="sixteen_nine" src="'.$instance['image'].'" width="300" height="169">';
- $output .= '<h3>'.$instance['title'].'</h3>';
- $output .= var_dump($instance['campus']);
- $output .= '<p>'.$instance['text'].' <a href="'.$instance['url'].'" title="Continue">Continue</a></p>';
- $output .= $after_widget;
- echo $output;
- }
- function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['campus'] = $new_instance['campus'];
- $instance['title'] = $new_instance['title'];
- $instance['image'] = $new_instance['image'];
- $instance['text'] = $new_instance['text'];
- $instance['url'] = $new_instance['url'];
- return $instance;
- }
- function form( $instance ) {
- $defaults = array(
- 'campus' => 'peoria',
- 'title' => 'Title Here',
- 'image' => '/images/16x9_blank.png',
- 'text' =>'default text',
- 'url' => 'http://www.google.com');
- $instance = wp_parse_args( (array) $instance, $defaults );
- ?>
- <p>
- <label for="<?php echo $this->get_field_id( 'campus' ); ?>">Campus: <?php echo $instance['campus']; ?></label>
- <select id="<?php echo $this->get_field_id( 'campus' ); ?>" name="<?php echo $this->get_field_id( 'campus' ); ?>">
- <?php
- foreach (campus_array() as $campus) {
- if ($instance['campus'] == $campus) $selected = 'selected="selected"';
- echo '<option value="'.$campus.'" id="'.$campus.'" '.$selected.'>'.ucwords($campus).'</option>';
- }
- ?>
- </select>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'title' ); ?>">Title:</label>
- <input id="<?php echo $this->get_field_id( 'title' ); ?>" name="<?php echo $this->get_field_name( 'title' ); ?>" style="width:100%;" value="<?php echo $instance['title']; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'image' ); ?>">Image :</label>
- <input id="<?php echo $this->get_field_id( 'image' ); ?>" name="<?php echo $this->get_field_name( 'image' ); ?>" style="width:100%;" value="<?php echo $instance['image']; ?>" />
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'text' ); ?>">HTML:</label>
- <textarea id="<?php echo $this->get_field_id( 'text' ); ?>" name="<?php echo $this->get_field_name( 'text' ); ?>" style="width:100%;min-height:100px;"><?php echo $instance['text']; ?></textarea>
- </p>
- <p>
- <label for="<?php echo $this->get_field_id( 'url' ); ?>">URL:</label>
- <input id="<?php echo $this->get_field_id( 'url' ); ?>" name="<?php echo $this->get_field_name( 'url' ); ?>" style="width:100%;" value="<?php echo $instance['url']; ?>" />
- </p>
- <?php }
- } //end widget class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement