Return to Snippet

Revision: 47223
at June 2, 2011 23:41 by willem


Updated Code
<?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) {		
        
        extract( $args );
        
        $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;
	$instance['title'] = strip_tags($new_instance['title']);
	$instance['body'] = trim($new_instance['body']);
	$instance['the_class'] = strip_tags($new_instance['the_class']);
        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
add_action('widgets_init', create_function('', 'return register_widget("TextWidgetClass");'));

?>

Revision: 47222
at June 2, 2011 23:40 by willem


Updated Code
<?php
/**
 * Text Widget With CSS Class
 * By Willem Bisschoff 
 */
 
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) {		
        
        extract( $args );
        
        $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;
	$instance['title'] = strip_tags($new_instance['title']);
	$instance['body'] = trim($new_instance['body']);
	$instance['the_class'] = strip_tags($new_instance['the_class']);
        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
add_action('widgets_init', create_function('', 'return register_widget("TextWidgetClass");'));

?>

Revision: 47221
at June 2, 2011 23:39 by willem


Updated Code
<?php
/**
 * Text Widget With CSS Class
 * By Willem Bisschoff 
 */
 
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) {		
        
        extract( $args );
        
        $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;
	$instance['title'] = strip_tags($new_instance['title']);
	$instance['body'] = trim($new_instance['body']);
	$instance['the_class'] = strip_tags($new_instance['the_class']);
        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 
    }

} // 

// register the widget
add_action('widgets_init', create_function('', 'return register_widget("TextWidgetClass");'));

?>

Revision: 47220
at June 2, 2011 23:37 by willem


Initial Code
<?php
/**
 * Text Widget With CSS Class
 * By Willem Bisschoff 
 */
 
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) {		
        
        extract( $args );
        
        $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;
	$instance['title'] = strip_tags($new_instance['title']);
	$instance['body'] = trim($new_instance['body']);
	$instance['the_class'] = strip_tags($new_instance['the_class']);
        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 
    }

} // 

// register the widget
add_action('widgets_init', create_function('', 'return register_widget("TextWidgetClass");'));

?>

Initial URL

                                

Initial Description

                                

Initial Title
Wordpress Text Widget with Class

Initial Tags
css, class, wordpress, text

Initial Language
PHP