-
Notifications
You must be signed in to change notification settings - Fork 2
/
widget.php
165 lines (130 loc) · 3.91 KB
/
widget.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
<?php
class Elementor_ACF_PO_Widget extends \Elementor\Widget_Base {
public function get_name() {
return 'acf_po';
}
public function get_title() {
return __( 'ACF Post Object List', 'elementor-acf-po-li-extension' );
}
public function get_icon() {
return 'eicon-bullet-list';
}
public function get_categories() {
return [ 'general' ];
}
protected function _register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => __( 'Post Object', 'elementor-acf-po-li-extension' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'title',
[
'label' => __( 'Title', 'elementor-acf-po-li-extension' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'placeholder' => __( 'Title Here', 'elementor-acf-po-li-extension' ),
]
);
$this->add_control(
'field',
[
'label' => __( 'ACF Field Slug', 'elementor-acf-po-li-extension' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'placeholder' => __( 'post_object', 'elementor-acf-po-li-extension' ),
'description' => __( 'This is the "Name" you assigned to your Post Object field in ACF.' ),
]
);
$this->add_control(
'seperator',
[
'label' => __( 'Seperator', 'elementor-acf-po-li-extension' ),
'type' => \Elementor\Controls_Manager::TEXT,
'input_type' => 'text',
'placeholder' => __( 'e.g. , | <br>', 'elementor-acf-po-li-extension' ),
]
);
$this->end_controls_section();
$this->start_controls_section(
'style_section',
[
'label' => __( 'Post Object', 'elementor-acf-po-li-extension' ),
'tab' => \Elementor\Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'title_color',
[
'label' => __( 'Title Color', 'elementor-acf-po-li-extension' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::get_default_scheme(),
],
'selectors' => [
'{{WRAPPER}} .acf-po-elementor-title' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'title_typography',
'label' => __( 'Title Typography', 'elementor-acf-po-li-extension' ),
'scheme' => \Elementor\Scheme_Typography::TYPOGRAPHY_1,
'selector' => '{{WRAPPER}} .acf-po-elementor-title',
]
);
$this->add_control(
'posts_color',
[
'label' => __( 'Posts Color', 'elementor-acf-po-li-extension' ),
'type' => \Elementor\Controls_Manager::COLOR,
'scheme' => [
'type' => \Elementor\Scheme_Color::get_type(),
'value' => \Elementor\Scheme_Color::get_default_scheme(),
],
'selectors' => [
'{{WRAPPER}} .acf-po-elementor-posts' => 'color: {{VALUE}}',
],
]
);
$this->add_group_control(
\Elementor\Group_Control_Typography::get_type(),
[
'name' => 'post_typography',
'label' => __( 'Posts Typography', 'elementor-acf-po-li-extension' ),
'scheme' => \Elementor\Scheme_Typography::TYPOGRAPHY_1,
'selector' => '{{WRAPPER}} .acf-po-elementor-posts',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
$title = $settings['title'];
$field = $settings['field'];
$seperator = $settings['seperator'];
$posts = get_field($field);
$html = '';
if( $posts ) {
$html .= '<span class="acf-po-elementor-title">'.$title.'</span>';
if (is_object($posts)) {
$html .= '<a class="acf-po-elementor-posts" href="'. $posts->guid . '">' . $posts->post_title . '</a>';
} else if (is_array($posts)) {
$count = count($posts);
foreach ($posts as $post) {
$html .= '<a class="acf-po-elementor-posts" href="'. $post->guid . '">' . $post->post_title . '</a>';
if (--$count > 0) {
$html .= $seperator;
}
}
}
}
echo ( $html );
}
}