Welbim_Projects.php (11593B)
1 <?php 2 namespace Welbim\Helper\Elementor\Widgets; 3 4 use Elementor\Utils; 5 use Elementor\Controls_Manager; 6 use Elementor\Widget_Base; 7 use Elementor\Plugin; 8 use \Elementor\Repeater; 9 use Elementor\Group_Control_Typography; 10 11 class Welbim_Projects extends Widget_Base { 12 13 14 public function get_name() { 15 return 'welbim_projects'; 16 } 17 18 public function get_title() { 19 return esc_html__( 'Welbim Projects', 'welbim' ); 20 } 21 22 public function get_icon() { 23 return 'sds-widget-ico'; 24 } 25 26 public function get_categories() { 27 return array( 'Welbim' ); 28 } 29 30 protected function _register_controls() { 31 $this->start_controls_section( 32 'general', 33 array( 34 'label' => esc_html__( 'General', 'welbim' ), 35 ) 36 ); 37 38 $this->add_control( 39 'layout_style', 40 array( 41 'label' => esc_html__( 'Layout Style', 'welbim' ), 42 'type' => Controls_Manager::SELECT, 43 'options' => array( 44 'style_1' => esc_html__( 'Style One', 'welbim' ), 45 'style_2' => esc_html__( 'Style Two', 'welbim' ), 46 'style_3' => esc_html__( 'Style Three', 'welbim' ), 47 ), 48 'default' => 'style_1', 49 ) 50 ); 51 52 $this->add_control( 53 'heading', 54 array( 55 'label' => esc_html__( 'Heading', 'welbim' ), 56 'type' => Controls_Manager::TEXT, 57 'default' => __( 'Recent projects', 'welbim' ), 58 'conditions' => array( 59 'relation' => 'or', 60 'terms' => array( 61 array( 62 'name' => 'layout_style', 63 'operator' => '==', 64 'value' => 'style_1', 65 ), 66 array( 67 'name' => 'layout_style', 68 'operator' => '==', 69 'value' => 'style_3', 70 ), 71 ), 72 ), 73 ) 74 ); 75 76 $this->add_control( 77 'sub_heading', 78 array( 79 'label' => esc_html__( 'Sub Heading', 'welbim' ), 80 'type' => Controls_Manager::TEXT, 81 'default' => __( 'Our Closed Projects', 'welbim' ), 82 'conditions' => array( 83 'relation' => 'or', 84 'terms' => array( 85 array( 86 'name' => 'layout_style', 87 'operator' => '==', 88 'value' => 'style_1', 89 ), 90 array( 91 'name' => 'layout_style', 92 'operator' => '==', 93 'value' => 'style_3', 94 ), 95 ), 96 ), 97 ) 98 ); 99 100 $this->end_controls_section(); 101 102 $this->start_controls_section( 103 'item', 104 array( 105 'label' => esc_html__( 'Item', 'welbim' ), 106 ) 107 ); 108 109 $repeater = new Repeater(); 110 111 $repeater->add_control( 112 'item_title', 113 array( 114 'label' => esc_html__( 'Title', 'welbim' ), 115 'type' => Controls_Manager::TEXT, 116 ) 117 ); 118 119 $repeater->add_control( 120 'item_image', 121 array( 122 'label' => esc_html__( 'Image', 'welbim' ), 123 'type' => Controls_Manager::MEDIA, 124 'default' => array( 125 'url' => Utils::get_placeholder_image_src(), 126 ), 127 128 ) 129 ); 130 131 $repeater->add_control( 132 'item_title_url', 133 array( 134 'label' => esc_html__( 'Title URL', 'welbim' ), 135 'type' => Controls_Manager::URL, 136 'placeholder' => esc_html__( 'https://your-link.com', 'welbim' ), 137 'show_external' => true, 138 'default' => array( 139 'url' => '', 140 'is_external' => false, 141 'nofollow' => false, 142 ), 143 ) 144 ); 145 146 $this->add_control( 147 'items', 148 array( 149 'label' => esc_html__( 'Repeater List', 'welbim' ), 150 'type' => Controls_Manager::REPEATER, 151 'fields' => $repeater->get_controls(), 152 'default' => array( 153 array( 154 'list_title' => esc_html__( 'Title #1', 'welbim' ), 155 'list_content' => esc_html__( 'Item content. Click the edit button to change this text.', 'welbim' ), 156 ), 157 array( 158 'list_title' => esc_html__( 'Title #2', 'welbim' ), 159 'list_content' => esc_html__( 'Item content. Click the edit button to change this text.', 'welbim' ), 160 ), 161 ), 162 ) 163 ); 164 165 $this->end_controls_section(); 166 167 // Typography Section 168 $this->start_controls_section( 169 'typography_section', 170 array( 171 'label' => __( 'Typography Section', 'welbim' ), 172 'tab' => Controls_Manager::TAB_STYLE, 173 ) 174 ); 175 176 $this->add_group_control( 177 Group_Control_Typography::get_type(), 178 array( 179 'name' => 'heading_typography', 180 'label' => __( 'Heading', 'welbim' ), 181 'selector' => '{{WRAPPER}} .sec-title h2', 182 183 ) 184 ); 185 186 $this->add_group_control( 187 Group_Control_Typography::get_type(), 188 array( 189 'name' => 'sub_heading_typography', 190 'label' => __( 'Sub Heading', 'welbim' ), 191 'selector' => '{{WRAPPER}} .sec-title .sub-title', 192 193 ) 194 ); 195 196 $this->add_group_control( 197 Group_Control_Typography::get_type(), 198 array( 199 'name' => 'item_title_typography', 200 'label' => __( 'Items Title ', 'welbim' ), 201 'selector' => '{{WRAPPER}} .project-block h4 a', 202 203 ) 204 ); 205 206 $this->end_controls_section(); 207 208 // Color Section 209 $this->start_controls_section( 210 'color_section', 211 array( 212 'label' => __( 'Color Section', 'welbim' ), 213 'tab' => \Elementor\Controls_Manager::TAB_STYLE, 214 ) 215 ); 216 217 $this->start_controls_tabs( 'tabs_button_style' ); 218 $this->start_controls_tab( 219 'tab_button_normal', 220 array( 221 'label' => __( 'Normal', 'welbim' ), 222 ) 223 ); 224 225 $this->add_control( 226 'heading_color', 227 array( 228 'label' => __( 'Heading Color', 'welbim' ), 229 'separator' => 'before', 230 'type' => \Elementor\Controls_Manager::COLOR, 231 'selectors' => array( 232 '{{WRAPPER}} .sec-title.light h2' => 'color: {{VALUE}}', 233 '{{WRAPPER}} .sec-title h2' => 'color: {{VALUE}}', 234 ), 235 ) 236 ); 237 238 $this->add_control( 239 'sub_heading_color', 240 array( 241 'label' => __( 'Sub Heading Color', 'welbim' ), 242 'separator' => 'before', 243 'type' => \Elementor\Controls_Manager::COLOR, 244 'selectors' => array( 245 '{{WRAPPER}} .projects-section .sec-title .sub-title' => 'color: {{VALUE}}', 246 '{{WRAPPER}} .sec-title .sub-title' => 'color: {{VALUE}}', 247 ), 248 ) 249 ); 250 251 $this->end_controls_tab(); 252 253 $this->start_controls_tab( 254 'tab_button_hover', 255 array( 256 'label' => __( 'Hover', 'welbim' ), 257 ) 258 ); 259 260 $this->add_control( 261 'title_color', 262 array( 263 'label' => __( 'Title Color', 'welbim' ), 264 'separator' => 'before', 265 'type' => \Elementor\Controls_Manager::COLOR, 266 'selectors' => array( 267 '{{WRAPPER}} .project-block h4 a:hover' => 'color: {{VALUE}}', 268 ), 269 ) 270 ); 271 272 $this->end_controls_tab(); 273 $this->end_controls_tabs(); 274 $this->end_controls_section(); 275 } 276 protected function render() { 277 $settings = $this->get_settings_for_display(); 278 $layout_style = $settings['layout_style']; 279 280 if ( $layout_style == 'style_1' ) { 281 $heading = $settings['heading']; 282 $sub_heading = $settings['sub_heading']; 283 ?> 284 <section class="projects-section"> 285 <div class="auto-container"> 286 <div class="sec-title text-center light"> 287 <div class="sub-title"><?php echo $sub_heading; ?></div> 288 <h2><?php echo $heading; ?></h2> 289 </div> 290 <div class="row"> 291 <?php 292 $i = 1; 293 foreach ( $settings['items'] as $item ) { 294 $item_title = $item['item_title']; 295 $item_image = ( $item['item_image']['id'] != '' ) ? wp_get_attachment_image( $item['item_image']['id'], 'full' ) : $item['item_image']['url']; 296 $item_image_alt = get_post_meta( $item['item_image']['id'], '_wp_attachment_image_alt', true ); 297 $item_title_url = $item['item_title_url']['url']; 298 $item_title_url_external = $item['item_title_url']['is_external'] ? 'target="_blank"' : ''; 299 $item_title_url_nofollow = $item['item_title_url']['nofollow'] ? 'rel="nofollow"' : ''; 300 ?> 301 <div class="col-xl-3 col-lg-6 project-block"> 302 <div class="inner-box"> 303 <div class="image"> 304 <?php 305 if ( wp_http_validate_url( $item_image ) ) { 306 ?> 307 <img src="<?php echo esc_url( $item_image ); ?>" alt="<?php esc_url( $item_image_alt ); ?>"> 308 <?php 309 } else { 310 echo $item_image; 311 } 312 ?> 313 </div> 314 <h4><a href=" <?php echo esc_url( $item_title_url ); ?>" <?php echo $item_title_url_external; ?> <?php echo $item_title_url_nofollow; ?>><?php echo $item_title; ?></a></h4> 315 </div> 316 </div> 317 <?php 318 $i++; 319 } 320 ?> 321 </div> 322 </div> 323 </section> 324 <?php } elseif ( $layout_style == 'style_2' ) { ?> 325 <!-- Projects section --> 326 <section class="projects-section style-two"> 327 <div class="auto-container"> 328 <div class="row"> 329 <?php 330 $i = 1; 331 foreach ( $settings['items'] as $item ) { 332 $item_title = $item['item_title']; 333 $item_image = ( $item['item_image']['id'] != '' ) ? wp_get_attachment_image( $item['item_image']['id'], 'full' ) : $item['item_image']['url']; 334 $item_image_alt = get_post_meta( $item['item_image']['id'], '_wp_attachment_image_alt', true ); 335 $item_title_url = $item['item_title_url']['url']; 336 $item_title_url_external = $item['item_title_url']['is_external'] ? 'target="_blank"' : ''; 337 $item_title_url_nofollow = $item['item_title_url']['nofollow'] ? 'rel="nofollow"' : ''; 338 ?> 339 <div class="col-lg-4 col-md-6 project-block"> 340 <div class="inner-box"> 341 <div class="image"> 342 <?php 343 if ( wp_http_validate_url( $item_image ) ) { 344 ?> 345 <img src="<?php echo esc_url( $item_image ); ?>" alt="<?php esc_url( $item_image_alt ); ?>"> 346 <?php 347 } else { 348 echo $item_image; 349 } 350 ?> 351 </div> 352 <h4><a href=" <?php echo esc_url( $item_title_url ); ?>" <?php echo $item_title_url_external; ?> <?php echo $item_title_url_nofollow; ?>><?php echo $item_title; ?></a></h4> 353 </div> 354 </div> 355 <?php 356 $i++; 357 } 358 ?> 359 </div> 360 </div> 361 </section> 362 <?php 363 } elseif ( $layout_style == 'style_3' ) { 364 $heading = $settings['heading']; 365 $sub_heading = $settings['sub_heading']; 366 ?> 367 368 <section class="related-projects"> 369 <div class="auto-container"> 370 <div class="sec-title text-center"> 371 <div class="sub-title"><?php echo $sub_heading; ?></div> 372 <h2><?php echo $heading; ?></h2> 373 </div> 374 <div class="row"> 375 <?php 376 $i = 1; 377 foreach ( $settings['items'] as $item ) { 378 $item_title = $item['item_title']; 379 $item_image = ( $item['item_image']['id'] != '' ) ? wp_get_attachment_image( $item['item_image']['id'], 'full' ) : $item['item_image']['url']; 380 $item_image_alt = get_post_meta( $item['item_image']['id'], '_wp_attachment_image_alt', true ); 381 $item_title_url = $item['item_title_url']['url']; 382 $item_title_url_external = $item['item_title_url']['is_external'] ? 'target="_blank"' : ''; 383 $item_title_url_nofollow = $item['item_title_url']['nofollow'] ? 'rel="nofollow"' : ''; 384 ?> 385 <div class="col-lg-4 col-md-6 project-block"> 386 <div class="inner-box"> 387 <div class="image"> 388 <?php 389 if ( wp_http_validate_url( $item_image ) ) { 390 ?> 391 <img src="<?php echo esc_url( $item_image ); ?>" alt="<?php esc_url( $item_image_alt ); ?>"> 392 <?php 393 } else { 394 echo $item_image; 395 } 396 ?> 397 </div> 398 <h4><a href=" <?php echo esc_url( $item_title_url ); ?>" <?php echo $item_title_url_external; ?> <?php echo $item_title_url_nofollow; ?>><?php echo $item_title; ?></a></h4> 399 </div> 400 </div> 401 <?php 402 $i++; 403 } 404 ?> 405 </div> 406 </div> 407 </section> 408 <?php 409 } 410 } 411 }