Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- *Custom Widget for call to action button 105x35px
- */
- add_action( 'widgets_init', 'button_widget' );
- function button_widget() {
- register_widget( 'Button_Widget' );
- }
- class Button_Widget extends WP_Widget {
- function Button_Widget() {
- $widget_ops = array( 'classname' => 'main-banner-button', 'description' => __('Displays widget for call to action button', 'button') );
- $control_ops = array( 'width' => 105, 'height' => 35, 'id_base' => 'button-widget' );
- $this->Button_Widget( 'button-widget', __('Button Widget', 'main-banner-button'), $widget_ops, $control_ops );
- }
- // Widget init
- public function __construct() {
- parent::__construct(
- 'button_widget',
- 'Custom Widget: Button Widget',
- array('description' => __('Button Widget','Displays widget for call to action button'), )
- );
- }
- // Output the Widget options in the back-end
- public function form($instance) {
- $defaults = array(
- 'title' => __('Button Widget'),
- 'ad_link' => 'http://wp.tutsplus.com',
- 'ad_img' => '/bg-btn.gif'
- );
- $instance = wp_parse_args((array) $instance, $defaults);
- ?>
- <!-- The Title -->
- <p>
- <label for="<?php echo $this->get_field_id('title') ?>"><?php _e('Title'); ?></label>
- <input type="text" id="<?php echo $this->get_field_id('title') ?>" name="<?php echo $this->get_field_name('title') ?>" class="widefat" value="<?php echo esc_attr($instance['title']); ?>" />
- </p>
- <!-- The Ad Link -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_link'); ?>"><?php _e('Ad Link'); ?></label>
- <input type="text" id="<?php echo $this->get_field_id('ad_link'); ?>" name="<?php echo $this->get_field_name('ad_link'); ?>" class="widefat" value="<?php echo esc_attr($instance['ad_link']); ?>" />
- </p>
- <!-- The Ad Image -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_img') ?>"><?php _e('Ad Image'); ?></label>
- <input type="text" id="<?php echo $this->get_field_id('ad_img') ?>" name="<?php echo $this->get_field_name('ad_img') ?>" class="widefat" value="<?php echo esc_attr($instance['ad_img']); ?>" />
- </p>
- <?php
- }
- // Process widget options for saving
- public function update($new_instance, $old_instance) {
- $instance = $old_instance;
- // Title
- $instance['title'] = strip_tags($new_instance['title']);
- // The Link
- $instance['ad_link'] = $new_instance['ad_link'];
- // The Image
- $instance['ad_img'] = $new_instance['ad_img'];
- return $instance;
- }
- //Displays the widget on the page
- public function widget($args, $instance) {
- extract($args);
- $title = apply_filters('widget-title', $instance['title']);
- $ad_img = $instance['ad_img'];
- $ad_link = $instance['ad_link'];
- echo $before_widget;
- if (isset($title)) {
- echo $before_title . $title . $after_title;
- }
- $text_link = '<a class="button">';
- if ($ad_img) {
- $text_link .= '<a class="button" href="<?php echo $ad_link; ?>"> Read More </a>';
- }
- $text_link .= '</a>';
- echo $text_link;
- echo $after_widget;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement