web/wp-content/themes/selecta/ocmx/widgets/advert-widget.php
author ymh
Fri, 12 Mar 2010 13:29:04 +0000
changeset 1 0d28b7c10758
permissions -rw-r--r--
First commit
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
0d28b7c10758 First commit
ymh
parents:
diff changeset
     1
<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
     2
class ocmx_small_ad_widget extends WP_Widget {
0d28b7c10758 First commit
ymh
parents:
diff changeset
     3
    /** constructor */
0d28b7c10758 First commit
ymh
parents:
diff changeset
     4
    function ocmx_small_ad_widget() {
0d28b7c10758 First commit
ymh
parents:
diff changeset
     5
        parent::WP_Widget(false, $name = 'OCMX 125 x 125 Adverts');	
0d28b7c10758 First commit
ymh
parents:
diff changeset
     6
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
     7
0d28b7c10758 First commit
ymh
parents:
diff changeset
     8
    /** @see WP_Widget::widget */
0d28b7c10758 First commit
ymh
parents:
diff changeset
     9
    function widget($args, $instance) {		
0d28b7c10758 First commit
ymh
parents:
diff changeset
    10
        extract( $args );
0d28b7c10758 First commit
ymh
parents:
diff changeset
    11
		if(get_option("ocmx_small_buysell_ads") == "on") :
0d28b7c10758 First commit
ymh
parents:
diff changeset
    12
			echo stripslashes(get_option("ocmx_small_buysell_id"));
0d28b7c10758 First commit
ymh
parents:
diff changeset
    13
		endif;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    14
		if(get_option("ocmx_small_ads") !== "0") :
0d28b7c10758 First commit
ymh
parents:
diff changeset
    15
			//To alternate the classes we set the right-handside class first
0d28b7c10758 First commit
ymh
parents:
diff changeset
    16
			$use_class == "advert right";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    17
			for ($i = 1; $i <= get_option("ocmx_small_ads"); $i++)
0d28b7c10758 First commit
ymh
parents:
diff changeset
    18
				{
0d28b7c10758 First commit
ymh
parents:
diff changeset
    19
					$ad_title_id = "ocmx_small_ad_title_".$i;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    20
					$ad_link_id = "ocmx_small_ad_link_".$i;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    21
					$ad_img_id ="ocmx_small_ad_img_".$i;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    22
					if(get_option($ad_img_id) !== "") :
0d28b7c10758 First commit
ymh
parents:
diff changeset
    23
						if($use_class == "advert") :
0d28b7c10758 First commit
ymh
parents:
diff changeset
    24
							$use_class = "advert right";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    25
						else :
0d28b7c10758 First commit
ymh
parents:
diff changeset
    26
							$use_class = "advert";
0d28b7c10758 First commit
ymh
parents:
diff changeset
    27
						endif;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    28
		?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    29
						<div class="<?php echo $use_class; ?>">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    30
							<a href="<?php echo get_option($ad_link_id); ?>" class="sponsor-item" title="<?php echo get_option($ad_title_id); ?>" rel="nofollow">
0d28b7c10758 First commit
ymh
parents:
diff changeset
    31
								<img src="<?php echo get_option($ad_img_id); ?>" alt="<?php echo get_option($ad_title_id); ?>" />
0d28b7c10758 First commit
ymh
parents:
diff changeset
    32
							</a>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    33
						</div>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    34
		<?php
0d28b7c10758 First commit
ymh
parents:
diff changeset
    35
					endif;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    36
				}				
0d28b7c10758 First commit
ymh
parents:
diff changeset
    37
		endif;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    38
		
0d28b7c10758 First commit
ymh
parents:
diff changeset
    39
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    40
0d28b7c10758 First commit
ymh
parents:
diff changeset
    41
    /** @see WP_Widget::update */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    42
    function update($new_instance, $old_instance) {
0d28b7c10758 First commit
ymh
parents:
diff changeset
    43
        return $new_instance;
0d28b7c10758 First commit
ymh
parents:
diff changeset
    44
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    45
0d28b7c10758 First commit
ymh
parents:
diff changeset
    46
    /** @see WP_Widget::form */
0d28b7c10758 First commit
ymh
parents:
diff changeset
    47
    function form($instance) {				
0d28b7c10758 First commit
ymh
parents:
diff changeset
    48
		
0d28b7c10758 First commit
ymh
parents:
diff changeset
    49
        ?>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    50
            <p><em>You can modify your sidebar ad's in the <a href="admin.php?page=ocmx-adverts">OCMX Options</a> panel</em></p>
0d28b7c10758 First commit
ymh
parents:
diff changeset
    51
        <?php 
0d28b7c10758 First commit
ymh
parents:
diff changeset
    52
    }
0d28b7c10758 First commit
ymh
parents:
diff changeset
    53
0d28b7c10758 First commit
ymh
parents:
diff changeset
    54
} // class FooWidget
0d28b7c10758 First commit
ymh
parents:
diff changeset
    55
0d28b7c10758 First commit
ymh
parents:
diff changeset
    56
//This sample widget can then be registered in the widgets_init hook:
0d28b7c10758 First commit
ymh
parents:
diff changeset
    57
0d28b7c10758 First commit
ymh
parents:
diff changeset
    58
// register FooWidget widget
0d28b7c10758 First commit
ymh
parents:
diff changeset
    59
add_action('widgets_init', create_function('', 'return register_widget("ocmx_small_ad_widget");'));
0d28b7c10758 First commit
ymh
parents:
diff changeset
    60
0d28b7c10758 First commit
ymh
parents:
diff changeset
    61
?>