control_groups['form'] = [ 'title' => esc_html__( 'Form', 'propertyhive' ), 'tab' => 'content', // content / style ];*/ } public function set_controls() { $this->controls['gallery_layout'] = [ 'tab' => 'content', //'group' => 'settings', 'label' => esc_html__( 'Layout', 'propertyhive' ), 'type' => 'select', 'options' => [ 'grid' => __( 'Six Images', 'propertyhive' ), 'one_large_four_small' => __( 'One Large Image, Four Small', 'propertyhive' ), ], //'inline' => true, //'clearable' => false, //'pasteStyles' => false, 'default' => 'grid', ]; $this->controls['start_at_image'] = [ // Unique control identifier (lowercase, no spaces) 'tab' => 'content', // Control tab: content/style //'group' => 'form', // Show under control group 'label' => esc_html__( 'Start at Image #', 'propertyhive' ), // Control label 'type' => 'text', // Control type 'default' => '1' ]; } public function render() { global $property; $settings = $this->settings; if ( !isset($property->id) ) { return; } $root_classes[] = $this->name; // Add 'class' attribute to element root tag $this->set_attribute( '_root', 'class', $root_classes ); echo "
render_attributes( '_root' )}>"; $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']) ? esc_attr($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']) ? esc_attr($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 } ?>
'; } }