function wpsight_do_listing_image($widget_width = '', $widget_location = '', $map = false) { // Get post id $post_id = get_the_ID(); if (empty($post_id)) { return; } // Don't show when password required if (post_password_required()) { return; } // Go on if there is a featured image if (has_post_thumbnail(get_the_ID())) { if (!empty($widget_width)) { // In case of a widget (lastest properties) $image_size = wpsight_get_layout_image('size_widget'); $image_align = wpsight_get_layout_image('align_widget'); // Set image size if ($widget_width == wpsight_get_span('half')) { $image_size = 'half'; } if ($widget_width == wpsight_get_span('big')) { $image_size = 'big'; } if ($widget_width == wpsight_get_span('full')) { $image_size = 'full'; } if ($widget_width == wpsight_get_span('small') || $widget_location == 'sidebar' || $widget_location == 'sidebar-home' || $widget_location == 'sidebar-page' || $widget_location == 'sidebar-post' || $widget_location == wpsight_get_sidebar('sidebar-listing') || $widget_location == wpsight_get_sidebar('sidebar-listing-archive')) { $image_size = 'post-thumbnail'; } // Remove image align $image_align = 'none'; // Limit images to box width and remove align if ($widget_width == wpsight_get_span('half') && ($image_size == 'half' || $image_size == 'big' || $image_size == 'full')) { $image_align = 'none'; } if (($widget_width == 'full' || $widget_width == wpsight_get_span('big')) && ($image_size == 'full' || $image_size == 'big') && $widget_location == 'home') { $image_align = 'none'; } if ($widget_location == 'sidebar' || $widget_location == 'sidebar-home' || $widget_width == wpsight_get_span('small')) { $image_align = 'none'; } } else { // Not in a widget but on archive pages $image_size = wpsight_get_layout_image('size_archive_listings'); $image_align = wpsight_get_layout_image('align_archive_listings'); // Get archive layout $archive_layout = wpsight_get_archive_layout('listing'); // Correct archive layout depending on sidebars if (($archive_layout == wpsight_get_span('half') || $archive_layout == wpsight_get_span('full')) && is_active_sidebar(wpsight_get_sidebar('sidebar-listing-archive'))) { $archive_layout = wpsight_get_span('big'); } if ($archive_layout == wpsight_get_span('big') && !is_active_sidebar(wpsight_get_sidebar('sidebar-listing-archive'))) { $archive_layout = wpsight_get_span('full'); } // Limit images to box width and remove align if ($archive_layout == wpsight_get_span('small')) { $image_size = 'post-thumbnail'; } if ($archive_layout == wpsight_get_span('half')) { $image_size = 'half'; } if ($archive_layout == wpsight_get_span('big')) { $image_size = 'big'; } if ($archive_layout == wpsight_get_span('full')) { $image_size = 'full'; } } // Filter image size $image_size = apply_filters('wpsight_do_listing_image_size', $image_size); // Filter image align $image_align = apply_filters('wpsight_do_listing_image_align', $image_align); // Create optional image overlay $overlay = apply_filters('wpsight_listing_image_overlay', false); // Remove link for favorites $remove = is_page_template('page-tpl-favorites.php') && empty($widget_location) ? '<span id="' . get_the_ID() . '" class="favorites-remove" title="' . __('Remove', 'wpsight') . '">' . __('Remove', 'wpsight') . '</span>' : ''; // Limit image size on properties map if (is_page_template('page-tpl-map.php') || $map === true) { $image_size = 'post-thumbnail'; } // Fincally output post image $image = '<div class="post-image listing-image align' . $image_align . '"><a href="' . get_permalink($post_id) . '">' . get_the_post_thumbnail($post_id, $image_size, array('alt' => the_title_attribute('echo=0'), 'title' => the_title_attribute('echo=0'))) . $overlay . $remove . '</a></div><!-- .post-image -->' . "\n"; echo $image = preg_replace('/\\s+/', ' ', $image); } }
function wpsight_do_post_image($widget_width = '', $widget_location = '') { // Get post id $post_id = get_the_ID(); if (empty($post_id)) { return; } // Stop here if images are disabled on single posts if (is_singular() && (wpsight_get_layout_image('show_on_single') == false && !is_page_template('page-tpl-blog.php'))) { return; } // Only show image on first page if multipage post global $page; if ($page != 1 && !is_page_template('page-tpl-blog.php')) { return; } // Go on if there is a featured image if (has_post_thumbnail(get_the_ID())) { if (!empty($widget_width)) { // In case of a widget (lastest posts) $image_size = wpsight_get_layout_image('size_widget'); $image_align = wpsight_get_layout_image('align_widget'); // Limit images to box width and remove align if ($widget_width == wpsight_get_span('half') && ($image_size == 'half' || $image_size == 'big' || $image_size == 'full')) { $image_align = 'none'; } if (($widget_width == 'full' || $widget_width == wpsight_get_span('big')) && ($image_size == 'full' || $image_size == 'big') && $widget_location == 'home') { $image_align = 'none'; } if ($widget_location == 'sidebar' || $widget_location == 'sidebar-home' || $widget_width == wpsight_get_span('small')) { $image_align = 'none'; } } elseif (is_singular() && !is_page_template('page-tpl-blog.php')) { // If this is a single post or a static page if (get_post_meta($post_id, '_image_size', true)) { // Respect individual post image settings $image_size = get_post_meta($post_id, '_image_size', true); } else { $image_size = wpsight_get_layout_image('size_single'); } // Set image align depending on layout if (get_post_meta($post_id, '_image_align', true)) { // Respect individual post image settings $image_align = get_post_meta($post_id, '_image_align', true); } else { $image_align = wpsight_get_layout_image('align_single'); } // Remove alignment in some cases if (is_single() && $image_size == 'big' && (is_active_sidebar('sidebar-post') || is_active_sidebar('sidebar')) && get_post_meta($post_id, '_layout', true) != 'full-width') { $image_align = 'none'; } if (is_page() && !is_page_template('page-tpl-blog.php') && $image_size == 'big' && (is_active_sidebar('sidebar-page') || is_active_sidebar('sidebar')) && get_post_meta($post_id, '_layout', true) != 'full-width') { $image_align = 'none'; } if ($image_size == 'full') { $image_align = 'none'; } } else { // Not in a widget nor on a single page but on archive pages $image_size = wpsight_get_layout_image('size_archive'); $image_align = wpsight_get_layout_image('align_archive'); // Set current archive if (is_tag()) { $archive = 'tag'; } elseif (is_author()) { $archive = 'author'; } elseif (is_date()) { $archive = 'date'; } elseif (is_search()) { $archive = 'search'; } else { $archive = 'category'; } // Get archive layout $archive_layout = wpsight_get_archive_layout($archive); // Limit images to box width and remove align if ($image_size == 'big' || $image_size == 'full') { $image_align = 'none'; } if ($archive_layout == wpsight_get_span('small')) { $image_align = 'none'; } } // Create optional image overlay $overlay = apply_filters('wpsight_post_image_overlay', false); // Fincally output post image if (is_singular() && !is_page_template('page-tpl-blog.php') && empty($widget_location)) { // Echo image on single posts and page withouth link tag echo '<div class="post-image align' . $image_align . '">' . get_the_post_thumbnail($post_id, $image_size, array('alt' => the_title_attribute('echo=0'), 'title' => the_title_attribute('echo=0'))) . $overlay . '</div><!-- .post-image -->' . "\n"; } else { echo '<div class="post-image align' . $image_align . '"><a href="' . get_permalink($post_id) . '">' . get_the_post_thumbnail($post_id, $image_size, array('alt' => the_title_attribute('echo=0'), 'title' => the_title_attribute('echo=0'))) . $overlay . '</a></div><!-- .post-image -->' . "\n"; } } }
function wpsight_meta_box_post_layouts() { // Post layouts labels $labels_layouts = array('image_size_label' => __('Image Size', 'wpsight'), 'image_size_description' => __('Keep in mind that the image size is limited by the layout', 'wpsight'), 'image_align_label' => __('Image Align', 'wpsight'), 'image_align_description' => __('Select your preferred image alignment', 'wpsight')); $labels_layouts = apply_filters('wpsight_meta_box_post_layouts_labels', $labels_layouts); $layouts = array('sidebar-right' => __('Right sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/sidebar-right.png' . '" class="layout-img" />', 'full-width' => __('No sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/full-width.png' . '" class="layout-img" />', 'sidebar-left' => __('Left sidebar', 'wpsight') . '<br /><img src="' . WPSIGHT_ADMIN_IMG_URL . '/sidebar-left.png' . '" class="layout-img" />'); $layouts = apply_filters('wpsight_meta_box_post_layouts_layouts', $layouts); if (empty($layouts)) { return; } // Get image sizes and create select data $image_sizes = array(); foreach (wpsight_image_sizes() as $k => $v) { $image_sizes[$k] = $v['label'] . ' (' . $v['size']['w'] . 'x' . $v['size']['h'] . 'px)'; } // Set image aligns $image_aligns = array('left' => __('left', 'wpsight'), 'right' => __('right', 'wpsight'), 'none' => __('none', 'wpsight')); $image_aligns = apply_filters('wpsight_meta_box_post_layouts_aligns', $image_aligns); // Set meta box $meta_box = array('id' => 'listing_layout', 'title' => wpsight_listing_layout_options('title'), 'pages' => array('post', 'page'), 'context' => 'normal', 'priority' => 'high', 'fields' => array('layout' => array('name' => wpsight_listing_layout_options('sidebar_label'), 'id' => '_layout', 'type' => 'radio', 'options' => $layouts, 'std' => 'sidebar-right'), 'size' => array('name' => $labels_layouts['image_size_label'], 'id' => '_image_size', 'type' => 'select', 'options' => $image_sizes, 'std' => 'big'), 'align' => array('name' => $labels_layouts['image_align_label'], 'id' => '_image_align', 'type' => 'select', 'options' => $image_aligns, 'std' => wpsight_get_layout_image('align_single')))); // Apply filter to array $meta_box = apply_filters('wpsight_meta_box_post_layouts', $meta_box); return $meta_box; }