start_controls_section( 'content_section', [ 'label' => __( 'Gallery', 'propertyhive' ), 'tab' => \Elementor\Controls_Manager::TAB_CONTENT, ] ); /*$this->add_control( 'padding', [ 'label' => __( 'Image Padding (px)', 'propertyhive' ), 'type' => \Elementor\Controls_Manager::TEXT, 'input_type' => 'number', 'default' => 0, ] );*/ $this->add_control( 'gallery_layout', [ 'label' => __( 'Layout', 'propertyhive' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => [ 'grid' => __( 'Six Images', 'propertyhive' ), 'one_large_four_small' => __( 'One Large Image, Four Small', 'propertyhive' ), ], 'default' => 'grid', ] ); $this->add_control( 'start_at_image', [ 'label' => __( 'Start at Image #', 'propertyhive' ), 'type' => \Elementor\Controls_Manager::NUMBER, 'default' => 1, 'min' => 1, ] ); $this->add_control( 'output_ratio', [ 'label' => __( 'Image Ratio', 'propertyhive' ), 'type' => \Elementor\Controls_Manager::SELECT, 'options' => [ '3:2' => __( '3:2', 'propertyhive' ), '4:3' => __( '4:3', 'propertyhive' ), '16:9' => __( '16:9', 'propertyhive' ), '1:1' => __( 'Square', 'propertyhive' ), ], 'default' => '4:3' ] ); $this->end_controls_section(); } protected function render() { global $property; $settings = $this->get_settings_for_display(); if ( !isset($property->id) ) { return; } $start_at_image = ( isset($settings['start_at_image']) && !empty($settings['start_at_image']) && is_numeric($settings['start_at_image']) ) ? ($settings['start_at_image'] - 1) : 0; $images = array(); $images_hidden = array(); if ( get_option('propertyhive_images_stored_as', '') == 'urls' ) { $photo_urls = $property->_photo_urls; if ( !is_array($photo_urls) ) { $photo_urls = array(); } if ( $start_at_image > 0 ) { $photo_urls_hidden = array_slice($photo_urls, 0, $start_at_image); foreach ( $photo_urls_hidden as $photo ) { $images_hidden[] = array( 'title' => isset($photo['title']) ? $photo['title'] : '', 'url' => isset($photo['url']) ? $photo['url'] : '', 'image' => '' . ( isset($photo['title']) ? $photo['title'] : '' ) . '', ); } } $photo_urls = array_slice($photo_urls, $start_at_image); foreach ( $photo_urls as $photo ) { $images[] = array( 'title' => isset($photo['title']) ? $photo['title'] : '', 'url' => isset($photo['url']) ? $photo['url'] : '', 'image' => '' . ( isset($photo['title']) ? $photo['title'] : '' ) . '', ); } } else { $gallery_attachments = $property->get_gallery_attachment_ids(); if ( !empty($gallery_attachments) ) { if ( $start_at_image > 0 ) { $gallery_attachments_hidden = array_slice($gallery_attachments, 0, $start_at_image); foreach ($gallery_attachments_hidden as $gallery_attachment) { $images_hidden[] = array( 'title' => esc_attr( get_the_title( $gallery_attachment ) ), 'url' => wp_get_attachment_url( $gallery_attachment ), 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ), 'attachment_id' => $gallery_attachment, ); } } $gallery_attachments = array_slice($gallery_attachments, $start_at_image); foreach ($gallery_attachments as $gallery_attachment) { $images[] = array( 'title' => esc_attr( get_the_title( $gallery_attachment ) ), 'url' => wp_get_attachment_url( $gallery_attachment ), 'image' => wp_get_attachment_image( $gallery_attachment, apply_filters( 'propertyhive_single_property_image_size', 'large' ) ), 'attachment_id' => $gallery_attachment, ); } } } if ( isset($images) && is_array($images) && !empty($images) ) { $settings['padding'] = 0; // hardcode to 0 for now. Make an option going forward. ?> '; ++$image_number; } ?> '; ++$image_number; } while ( count($images) > ($image_number) ) { echo ''; ++$image_number; } // Code second layout, for one main photo } ?>