Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // get sidebar
- <div class="cw_single">
- <?php get_sidebar(); ?>
- </div>
- //Custom widget
- <?php
- class Adaptive_Ad_260_Widget extends WP_Widget {
- // widget init
- public function __construct() {
- parent::__construct(
- 'adaptice_ad_w',
- 'Custom Widget: 260x120 Ad',
- array('description' => __('Display a single 260x120 ad block', 'custom_widget')) //custom_widget text domain
- );
- }
- // output the widget options in the back-end
- public function form($instance) {
- $defaults = array(
- 'title' => __('Ad 260x120', 'custom_widget'),
- 'ad_img' => IMAGES . '/quote-format-icon.png',
- 'ad_link' => 'http://wp.tutsplus.com',
- 'dsc' => __('Description', 'custom_widget'),
- );
- $instance = wp_parse_args((array) $instance, $defaults);
- ?>
- <!-- title -->
- <p>
- <label for="<?php echo $this->get_field_id('title') ?>"><?php _e('Title', 'custom_widget'); ?></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>
- <!-- ad image -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_img') ?>"><?php _e('Ad Image', 'custom_widget'); ?></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>
- <!-- ad link -->
- <p>
- <label for="<?php echo $this->get_field_id('ad_link') ?>"><?php _e('Ad Link', 'custom_widget'); ?></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>
- <?php
- }
- // Process widget options for saving
- public function update($new_instance, $old_instance) {
- $instance = $old_instance;
- // Title
- $instance['title'] = strip_tags($new_instance['title']);
- // Ad image
- $instance['ad_img'] = strip_tags($new_instance['ad_img']);
- // Ad link
- $instance['ad_link'] = strip_tags($new_instance['ad_link']);
- return $instance;
- }
- // Display 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'];
- if ($title) {
- echo $before_title . $title . $after_title;
- }
- echo '<div class="cw_single">';
- if($ad_img) : ?>
- <a href="<?php echo $ad_link; ?>"><img src="<?php echo $ad_img ?>" alt=""></a>
- <?php endif;
- echo '</div>';
- echo $after_widget;
- }
- }
- register_widget('Adaptive_Ad_260_Widget');
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement