-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-widget-2.php
125 lines (112 loc) · 2.53 KB
/
example-widget-2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<?php
/*
Plugin Name: Lion2486 example Widget 2
Plugin URI: http://codescar.eu
Description: An example widget using Lion2486 Widget Class.
Version: 1.01
Author: lion2486
Author URI: http://codescar.eu
License: None
*/
/**
* Example Widget 2 based on lion2486-widget class.
*/
require_once( __DIR__ . '/lion2486-widget.php' );
class Image_Page_header_Widget extends Lion2486_Widget {
//The widget ID, must be unique! (optional, if NULL, class name is used).
protected $WidgetID = "image_page_header_widget";
//WidgetDescription. Text to show on widget list (optional).
protected $WidgetDescription = "Widget to display an image as header of the page.";
//text domain for translations.
protected $textDomain = 'html5blank';
//Widget Name! (Human readable form)
protected $WidgetName = "Page Image Header";
public function __construct( ) {
//Call the parent::__constructor()
parent::__construct();
//Here set your own fields.
$this->fields = array(
$this->field(
'image_id',
'Image',
'',
'media'
),
$this->field(
'icon_id',
'Icon',
'',
'media'
),
$this->field(
'small_title',
'Small Title'
),
$this->field(
'title',
'Title'
),
$this->field(
'body',
'Text Body',
'',
'textarea'
),
$this->field(
'bg_color',
'Background Color',
'',
array(
'dataType' => 'input',
'attr' => array(
'type' => 'color'
)
),
'#143260'
),
$this->field(
'opacity',
'Background Opacity',
'',
array(
'dataType' => 'input',
'attr' => array(
'type' => 'range',
'min' => '0',
'max' => '1',
'step' => '0.05'
)
),
'0.35'
)
);
}
public function widget( $args, $instance ) {
extract( $vars = $this->form_fields( $instance ) );
$page = get_post( $vars['page_id'] );
if(!$page)
return;
echo "
<div class='page-header-image-container' style='
background-image: url(\"" . wp_get_attachment_url( $vars['image_id'] ) . "\");
background-size: cover;
//position: absolute;
top: 0;
width: 100%;
height: 46vw;
' >
<div class='content' style='
width: 100%;
height: 100%;
background-color: {$vars['bg_color']};
opacity: {$vars['opacity']};
'>
<img src='" . wp_get_attachment_url( $vars['icon_id']) . "' alt='{$vars['title']}' />
<h4>{$vars['small_title']}</h4>
<h1>{$vars['title']}</h1>
<p>{$vars['body']}</p>
</div>
</div>";
}
};
new Image_Page_header_Widget();