Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save propertyhive/f8652641b9b2ee14ae9ad28721c812a6 to your computer and use it in GitHub Desktop.
Save propertyhive/f8652641b9b2ee14ae9ad28721c812a6 to your computer and use it in GitHub Desktop.
Output Houzez images stored as URLs
function houzez_get_property_gallery($size = 'thumbnail')
{
global $post;
if ( ! houzez_option('disable_property_gallery', 1) ) {
return;
}
if ( get_post_meta($post->ID, 'images_stored_as_urls', true) === '1' )
{
$image_urls = get_post_meta($post->ID, 'image_urls', true);
$images = array();
if (!empty($image_urls) && is_array($image_urls))
{
foreach ($image_urls as $image_url)
{
$images[] = array(
'image' => $image_url['url'],
'alt' => '',
);
}
}
return 'data-images="'.esc_attr(json_encode($images)).'"';
}
else
{
$gallery_ids = get_post_meta( $post->ID, 'fave_property_images', false );
if ( has_post_thumbnail() || $gallery_ids ) {
$images = [];
$temp_array = [];
if ( has_post_thumbnail() && houzez_option('featured_img_in_gallery', 0) != 1 ) {
$thumb_id = get_post_thumbnail_id($post);
$thumb_meta = wp_get_attachment_metadata($thumb_id);
$temp_array['image'] = get_the_post_thumbnail_url($post, $size);
$temp_array['alt'] = get_post_meta( $thumb_id, '_wp_attachment_image_alt', true );
if (isset($thumb_meta['sizes'][$size])) {
$temp_array['width'] = $thumb_meta['sizes'][$size]['width'];
$temp_array['height'] = $thumb_meta['sizes'][$size]['height'];
}
$images[] = $temp_array;
}
if ( empty($gallery_ids) ) {
return;
}
foreach ( $gallery_ids as $id ) {
$img = wp_get_attachment_image_url($id, $size);
$img_meta = wp_get_attachment_metadata($id);
$alt_text = get_post_meta( $id, '_wp_attachment_image_alt', true );
if ( $img ) {
$temp_array['image'] = $img;
$temp_array['alt'] = $alt_text;
if (isset($img_meta['sizes'][$size])) {
$temp_array['width'] = $img_meta['sizes'][$size]['width'];
$temp_array['height'] = $img_meta['sizes'][$size]['height'];
}
$images[] = $temp_array;
}
}
return ' data-images="'.esc_attr(json_encode($images)).'"';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment