/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php /** * Text Widget With CSS Class * */ class TextWidgetClass extends WP_Widget { //Constructor function TextWidgetClass() { parent::WP_Widget(false, $name = 'Text Widget With Class'); } // The Widget (front-end) function widget($args, $instance) { $title = apply_filters( 'widget_title', $instance['title'] ); $body = apply_filters( 'widget_body', $instance['body'] ); $the_class = apply_filters( 'widget_body', $instance['the_class'] ); ?> <li <?php echo 'id=""' . "class='text_widget_class $the_class'"; ?> > <?php if ( $title ) ?> <?php echo $before_title . $title . $after_title; ?> <?php echo '<p>' . $body . '</p>'; ?> </li> <?php } // Udpate Widget function update($new_instance, $old_instance) { $instance = $old_instance; return $instance; } // Display Widget From function form($instance) { $title = esc_attr($instance['title']); $body = esc_attr($instance['body']); $the_class= esc_attr($instance['the_class']); ?> <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 $title; ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('the_class'); ?>"><?php _e('Class:'); ?></label> <input class="widefat" id="<?php echo $this->get_field_id('the_class'); ?>" name="<?php echo $this->get_field_name('the_class'); ?>" type="text" value="<?php echo $the_class; ?>" /> </p> <p> <label for="<?php echo $this->get_field_id('body'); ?>"><?php _e('Body:'); ?></label> <textarea class="widefat" rows="16" colls="20" id="<?php echo $this->get_field_id('body'); ?>" name="<?php echo $this->get_field_name('body'); ?>"><?php echo $body; ?></textarea> </p> <?php } } // end class // register the widget ?>