Created
March 18, 2019 16:10
-
-
Save accessomnath/a0b5a388a4938e43ad649593a5508018 to your computer and use it in GitHub Desktop.
Widget add
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class widget_simple extends WP_Widget { | |
// Create Widget | |
function widget_simple() { | |
parent::WP_Widget(false, $name = 'Custom Simple Widget', array('description' => '')); | |
} | |
// Widget Content | |
function widget($args, $instance) { | |
extract( $args ); | |
$simple_image_url = strip_tags($instance['simple_image_url']); | |
$simple_image_link = strip_tags($instance['simple_image_link']); | |
$simple_title = strip_tags($instance['simple_title']); | |
$simple_title_link = strip_tags($instance['simple_title_link']); | |
$simple_text = strip_tags($instance['simple_text']); | |
?> | |
<div id="latest-box"> | |
<span class="img-box"> | |
<a href="<?php echo $simple_image_link; ?>"><img src="<?php echo $simple_image_url; ?>"></a> | |
</span> <!-- img-box --> | |
<span class="latest-title"> | |
<a href="<?php echo $simple_title_link; ?>"><?php echo $simple_title; ?></a> | |
</span> <!-- title --> | |
<span class="latest-text"> | |
<?php echo $simple_text; ?> | |
</span> <!-- text --> | |
</div> <!-- box --> | |
<?php | |
} | |
// Update and save the widget | |
function update($new_instance, $old_instance) { | |
return $new_instance; | |
} | |
// If widget content needs a form | |
function form($instance) { | |
//widgetform in backend | |
$simple_image_url = strip_tags($instance['simple_image_url']); | |
$simple_image_link = strip_tags($instance['simple_image_link']); | |
$simple_title = strip_tags($instance['simple_title']); | |
$simple_title_link = strip_tags($instance['simple_title_link']); | |
$simple_text = strip_tags($instance['simple_text']); | |
?> | |
<p> | |
<label for="<?php echo $this->get_field_id('simple_image_url'); ?>">Image URL: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id('simple_image_url'); ?>" name="<?php echo $this->get_field_name('simple_image_url'); ?>" type="text" value="<?php echo attribute_escape($simple_image_url); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('simple_image_link'); ?>">Image Link: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id('simple_image_link'); ?>" name="<?php echo $this->get_field_name('simple_image_link'); ?>" type="text" value="<?php echo attribute_escape($simple_image_link); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('simple_title'); ?>">Title: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id('simple_title'); ?>" name="<?php echo $this->get_field_name('simple_title'); ?>" type="text" value="<?php echo attribute_escape($simple_title); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('simple_title_link'); ?>">Title Link: </label> | |
<input class="widefat" id="<?php echo $this->get_field_id('simple_title_link'); ?>" name="<?php echo $this->get_field_name('simple_title_link'); ?>" type="text" value="<?php echo attribute_escape($simple_title_link); ?>" /> | |
</p> | |
<p> | |
<label for="<?php echo $this->get_field_id('simple_text'); ?>">Text: </label> | |
<textarea class="widefat" id="<?php echo $this->get_field_id('simple_text'); ?>" name="<?php echo $this->get_field_name('simple_text'); ?>"><?php echo attribute_escape($simple_text); ?></textarea> | |
</p> | |
<?php | |
} | |
} | |
register_widget('widget_simple'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment