1
|
1 |
<?php |
|
2 |
class ocmx_small_ad_widget extends WP_Widget { |
|
3 |
/** constructor */ |
|
4 |
function ocmx_small_ad_widget() { |
|
5 |
parent::WP_Widget(false, $name = 'OCMX 125 x 125 Adverts'); |
|
6 |
} |
|
7 |
|
|
8 |
/** @see WP_Widget::widget */ |
|
9 |
function widget($args, $instance) { |
|
10 |
extract( $args ); |
|
11 |
if(get_option("ocmx_small_buysell_ads") == "on") : |
|
12 |
echo stripslashes(get_option("ocmx_small_buysell_id")); |
|
13 |
endif; |
|
14 |
if(get_option("ocmx_small_ads") !== "0") : |
|
15 |
//To alternate the classes we set the right-handside class first |
|
16 |
$use_class == "advert right"; |
|
17 |
for ($i = 1; $i <= get_option("ocmx_small_ads"); $i++) |
|
18 |
{ |
|
19 |
$ad_title_id = "ocmx_small_ad_title_".$i; |
|
20 |
$ad_link_id = "ocmx_small_ad_link_".$i; |
|
21 |
$ad_img_id ="ocmx_small_ad_img_".$i; |
|
22 |
if(get_option($ad_img_id) !== "") : |
|
23 |
if($use_class == "advert") : |
|
24 |
$use_class = "advert right"; |
|
25 |
else : |
|
26 |
$use_class = "advert"; |
|
27 |
endif; |
|
28 |
?> |
|
29 |
<div class="<?php echo $use_class; ?>"> |
|
30 |
<a href="<?php echo get_option($ad_link_id); ?>" class="sponsor-item" title="<?php echo get_option($ad_title_id); ?>" rel="nofollow"> |
|
31 |
<img src="<?php echo get_option($ad_img_id); ?>" alt="<?php echo get_option($ad_title_id); ?>" /> |
|
32 |
</a> |
|
33 |
</div> |
|
34 |
<?php |
|
35 |
endif; |
|
36 |
} |
|
37 |
endif; |
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
/** @see WP_Widget::update */ |
|
42 |
function update($new_instance, $old_instance) { |
|
43 |
return $new_instance; |
|
44 |
} |
|
45 |
|
|
46 |
/** @see WP_Widget::form */ |
|
47 |
function form($instance) { |
|
48 |
|
|
49 |
?> |
|
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> |
|
51 |
<?php |
|
52 |
} |
|
53 |
|
|
54 |
} // class FooWidget |
|
55 |
|
|
56 |
//This sample widget can then be registered in the widgets_init hook: |
|
57 |
|
|
58 |
// register FooWidget widget |
|
59 |
add_action('widgets_init', create_function('', 'return register_widget("ocmx_small_ad_widget");')); |
|
60 |
|
|
61 |
?> |