/** * Lightbox * * @since 1.1.0 * * @param array $atts Standard WordPress shortcode attributes * @param string $content Content in shortcode * @return string $output Content to output for shortcode */ function themeblvd_shortcode_lightbox($atts, $content = null) { // Shortcode requires framework 2.3+ if (!function_exists('themeblvd_is_lightbox_url')) { $error = __('You must be using a theme with Theme Blvd framework v2.3+ to use the [lightbox] shortcode.', 'themeblvd_shortcodes'); return sprintf('<div class="alert">%s</div>', $error); } $default = array('link' => '', 'thumb' => '', 'caption' => '', 'width' => '', 'align' => 'none', 'title' => '', 'frame' => 'true', 'frame_max' => 'true', 'icon' => 'image', 'class' => ''); $atts = shortcode_atts($default, $atts); $output = ''; // Setup thumbnail, can be image or text string $thumb = $atts['thumb']; $has_thumb_img = false; $thumb_type = wp_check_filetype($thumb); if (substr($thumb_type['type'], 0, 5) == 'image') { $has_thumb_img = true; // Build <img /> HTML for thumbnail $thumb = sprintf('<img src="%s" alt="%s"', $thumb, $atts['title']); if ($atts['width']) { $thumb .= sprintf(' width="%s"', $atts['width']); } if ($atts['frame'] == 'false' && $atts['align'] != 'none') { // If image is framed, the alignment will be on the frame $thumb .= sprintf(' class="align%s"', $atts['align']); } $thumb .= ' />'; } // Add image overlay if framed thumbnail if ($atts['frame'] == 'true' && $has_thumb_img) { $thumb .= themeblvd_get_image_overlay(); } // Classes for link's anchor tag $anchor_classes = ''; if ($atts['frame'] == 'true') { $anchor_classes .= 'thumbnail ' . $atts['icon']; } if ($atts['frame'] == 'false' && $atts['class']) { $anchor_classes .= $atts['class']; } if ($atts['caption']) { $anchor_classes .= ' has-caption'; } // Wrap thumbail image/text in link to lightbox $args = apply_filters('themeblvd_lightbox_shortcode_args', array('item' => $thumb, 'link' => $atts['link'], 'title' => $atts['title'], 'class' => $anchor_classes), $atts); $output .= themeblvd_get_link_to_lightbox($args); // Wrap link and thumbnail image in frame if ($atts['frame'] == 'true' && $has_thumb_img) { // Wrapping CSS classes $wrap_classes = 'tb-lightbox-shortcode'; if ($atts['align'] != 'none') { $wrap_classes .= ' align' . $atts['align']; } if ($atts['class']) { $wrap_classes .= ' ' . $atts['class']; } // Force inline styling $style = ''; if ($atts['width'] && $atts['frame_max'] == 'true') { $style = sprintf('max-width: %spx', $atts['width']); } $wrap = '<div class="' . $wrap_classes . '" style="' . $style . '">'; $wrap .= '<div class="featured-image-wrapper">'; $wrap .= '<div class="featured-image">'; $wrap .= '<div class="featured-image-inner">'; $wrap .= '%s'; // Caption if ($atts['caption']) { $wrap .= sprintf('<p class="wp-caption-text">%s</p>', $atts['caption']); } $wrap .= '</div><!-- .featured-image-inner (end) -->'; $wrap .= '</div><!-- .featured-image (end) -->'; $wrap .= '</div><!-- .featured-image-wrapper (end) -->'; $wrap .= '</div>'; $wrap = apply_filters('themeblvd_lightbox_shortcode_thumbnail_wrap', $wrap, $wrap_classes, $style); $output = sprintf($wrap, $output); } else { if ($atts['caption']) { $output .= sprintf('<p class="wp-caption-text">%s</p>', $atts['caption']); } } return apply_filters('themeblvd_shortcode_lightbox', $output, $atts, $thumb); }
/** * Get Mini Post Grid * * @since 2.1.0 * * @param array $options Options for many post grid * @return string $output HTML to output */ function themeblvd_get_mini_post_grid($query = '', $align = 'left', $thumb = 'smaller', $gallery = '') { global $post; global $_wp_additional_image_sizes; $output = ''; // CSS classes $classes = $thumb . '-thumbs'; $classes .= ' grid-align-' . $align; if ($gallery) { $classes .= ' gallery-override themeblvd-gallery'; } // Thumb size $thumb_size = apply_filters('themeblvd_mini_post_grid_thumb_size', 'square_' . $thumb, $thumb, $query); $thumb_width = $_wp_additional_image_sizes[$thumb_size]['width']; // Check for gallery override $gallery_link = ''; if ($gallery) { $pattern = get_shortcode_regex(); if (preg_match("/{$pattern}/s", $gallery, $match) && 'gallery' == $match[2]) { $atts = shortcode_parse_atts($match[3]); if (isset($atts['link']) && 'file' == $atts['link']) { $gallery_link = 'file'; } if (!empty($atts['ids'])) { $query = array('post_type' => 'attachment', 'post__in' => explode(',', $atts['ids']), 'posts_per_page' => -1); } } } // Format query if (!is_array($query)) { $query = html_entity_decode($query); } // Get posts $posts = get_posts($query); // Start output if ($posts) { $output = '<div class="themeblvd-mini-post-grid">'; $output .= '<ul class="' . $classes . '">'; foreach ($posts as $post) { setup_postdata($post); $output .= '<li>'; if ($gallery) { // Gallery image output to simulate featured images $thumbnail = wp_get_attachment_image_src($post->ID, apply_filters('themeblvd_mini_post_grid_thumb_size', 'square_' . $thumb, $thumb, $query, $align, $gallery)); $output .= '<div class="featured-image-wrapper">'; $output .= '<div class="featured-image">'; $output .= '<div class="featured-image-inner">'; if ('file' == $gallery_link) { $image = wp_get_attachment_image_src($post->ID, 'full'); $item = sprintf('<img src="%s" alt="%s" />', $thumbnail[0], $post->post_title); $args = array('item' => $item . themeblvd_get_image_overlay(), 'link' => $image[0], 'title' => $post->post_title, 'class' => 'image thumbnail', 'gallery' => true); $output .= themeblvd_get_link_to_lightbox($args); } else { $output .= sprintf('<a href="%s" title="%s" class="image thumbnail">', get_permalink($post->ID), $post->post_title, $gallery); $output .= sprintf('<img src="%s" alt="%s" />', $thumbnail[0], $post->post_title); $output .= themeblvd_get_image_overlay(); $output .= '</a>'; } $output .= '</div><!-- .featured-image-inner (end) -->'; $output .= '</div><!-- .featured-image (end) -->'; $output .= '</div><!-- .featured-image-wrapper (end) -->'; } else { // Standard featured image output $image = themeblvd_get_post_thumbnail('primary', $thumb_size); // If post thumbnail isn't set, pull default thumbnail // based on post format. If theme doesn't support post // formats, format will always be "standard". if (!$image) { $default_img_directory = apply_filters('themeblvd_thumbnail_directory', get_template_directory_uri() . '/framework/assets/images/thumbs/2x/'); $post_format = get_post_format(); if (!$post_format) { $post_format = 'standard'; } $image .= '<div class="featured-image-wrapper attachment-' . $thumb_size . ' thumbnail">'; $image .= '<div class="featured-image">'; $image .= '<div class="featured-image-inner">'; $image .= sprintf('<a href="%s" title="%s">', get_permalink(), get_the_title()); $image .= sprintf('<img src="%s.png" width="%s" class="wp-post-image" />', $default_img_directory . $thumb . '_' . $post_format, $thumb_width); $image .= '</a>'; $image .= '</div><!-- .featured-image-inner (end) -->'; $image .= '</div><!-- .featured-image (end) -->'; $image .= '</div><!-- .featured-image-wrapper (end) -->'; } $output .= $image; } $output .= '</li>'; } wp_reset_postdata(); $output .= '</ul>'; $output .= '<div class="clear"></div>'; $output .= '</div><!-- .themeblvd-mini-post-list (end) -->'; } else { $output = themeblvd_get_local('archive_no_posts'); } return $output; }
/** * Get the final image output for an image slide * * @since 1.1.0 * * @param array $atts Media attributes from themeblvd_sliders_get_media_atts() * @param string $slider_type Type of slider, standard, nivo, carrousel, bootstrap, or fallback * @return string $output HTML output for image */ function themeblvd_sliders_get_image($atts, $slider_type = 'standard') { $lightbox = false; $output = ''; $link_target = ''; // Image $image = sprintf('<img src="%s" alt="%s" width="%s" height="%s" />', $atts['url'], $atts['alt'], $atts['width'], $atts['height']); // Image Link if ($atts['link']) { // Link class and target switch ($atts['link']['target']) { case 'lightbox_video': $lightbox = true; $anchor_class = 'slide-thumbnail-link video'; break; case 'lightbox': $lightbox = true; $anchor_class = 'slide-thumbnail-link image'; break; case '_blank': $anchor_class = 'slide-thumbnail-link external'; $link_target = $atts['link']['target']; break; default: $anchor_class = 'slide-thumbnail-link post'; $link_target = $atts['link']['target']; } // Markup used for image overlay in to work with framework javascript $overlay = ''; if ($slider_type != 'fallback') { if (function_exists('themeblvd_get_image_overlay')) { $overlay = themeblvd_get_image_overlay(); } else { $overlay = '<span class="image-overlay"><span class="image-overlay-bg"></span><span class="image-overlay-icon"></span></span>'; } } $overlay = apply_filters('themeblvd_sliders_image_overlay', $overlay, $atts, $link_target, $slider_type); // Wrap image in link if ($lightbox && function_exists('themeblvd_get_link_to_lightbox')) { $args = apply_filters('themeblvd_sliders_lightbox_args', array('item' => $image . $overlay, 'link' => $atts['link']['url'], 'class' => $anchor_class, 'title' => $atts['link']['title']), $atts, $image, $slider_type); $output = themeblvd_get_link_to_lightbox($args); } else { $output = sprintf('<a href="%s" title="%s" target="%s" class="%s">%s</a>', $atts['link']['url'], $atts['link']['title'], $link_target, $anchor_class, $image . $overlay); } } else { // Output set to the raw image when there's no link $output .= $image; } return apply_filters('themeblvd_sliders_image', $output, $atts, $image, $slider_type, $lightbox); }
/** * The post thumbnail (must be within the loop) * * @since 2.0.0 * * @param string $location Where the thumbnail is being used -- primary, featured, single -- sort of a wild card to build on in the future as conflicts arise. * @param string $size For the image crop size of the thumbnail * @param bool $link Set to false to force a thumbnail to ignore post's Image Link options * @param bool $allow_filters Whether to allow general filters on the thumbnail or not * @return string $output HTML to output thumbnail */ function themeblvd_get_post_thumbnail($location = 'primary', $size = '', $link = true, $allow_filters = true) { global $post; $attachment_id = get_post_thumbnail_id($post->ID); $sidebar_layout = themeblvd_config('sidebar_layout'); $lightbox = false; $link_target = ''; $link_url = ''; $anchor_class = ''; $output = ''; $classes = ''; $image = ''; $title = ''; // If no thumbnail, we can skip everything. However, // we still want plugins to be able to filter in here // however they want. This same filter is applied below // on the final output. if (!has_post_thumbnail($post->ID) && $allow_filters) { return apply_filters('themeblvd_post_thumbnail', '', $location, $size, $link); } // Determine correct thumbnail size string, or if wasn't // passed in, get a fallback based on framework options. $size = themeblvd_get_thumbnail_size($size, $location, $sidebar_layout); // If $size was set to null, it means the post // thumb should be hidden. So, return nothing. if ($size === null) { return $output; } // Can we just skip the featured image? $thumb_link_meta = get_post_meta($post->ID, '_tb_thumb_link', true); // used below in determining featured image link if ($thumb_link_meta == 'inactive') { $link = false; } // How about skipping featured image link on the single post? if ($link && $location == 'single' && get_post_meta($post->ID, '_tb_thumb_link_single', true) == 'no') { $link = false; } // Determine link for featured image if ($link) { $possible_link_options = array('post', 'thumbnail', 'image', 'video', 'external'); if (in_array($thumb_link_meta, $possible_link_options)) { switch ($thumb_link_meta) { case 'post': $title = get_the_title(); $link_url = get_permalink($post->ID); break; case 'thumbnail': $title = get_the_title($attachment_id); $link_url = wp_get_attachment_url($attachment_id); $lightbox = true; break; case 'image': $title = get_the_title(); $link_url = get_post_meta($post->ID, '_tb_image_link', true); $lightbox = true; break; case 'video': $title = get_the_title($attachment_id); $link_url = get_post_meta($post->ID, '_tb_video_link', true); $lightbox = true; break; case 'external': $link_url = get_post_meta($post->ID, '_tb_external_link', true); $link_target = get_post_meta($post->ID, '_tb_external_link_target', true); if (!$link_target) { $link_target = '_blank'; } break; } } else { $link = false; } } // Attributes $size_class = $size; if ($size_class == 'tb_small') { $size_class = 'small'; } $classes = 'attachment-' . $size_class . ' wp-post-image'; if (!$link) { $classes .= ' thumbnail'; } else { $anchor_class = 'thumbnail'; if ($thumb_link_meta != 'thumbnail') { $anchor_class .= ' ' . $thumb_link_meta; } } // Initial image without link $image = get_the_post_thumbnail($post->ID, $size, array('class' => '')); // Wrap image in link if ($link) { if ($lightbox) { $args = apply_filters('themeblvd_featured_image_lightbox_args', array('item' => $image . themeblvd_get_image_overlay(), 'link' => $link_url, 'class' => $anchor_class, 'title' => $title), $post->ID, $attachment_id); $image = themeblvd_get_link_to_lightbox($args); } else { $image = sprintf('<a href="%s" target="%s" class="%s" title="%s">%s%s</a>', $link_url, $link_target, $anchor_class, $title, $image, themeblvd_get_image_overlay()); } } // Final HTML output $output .= '<div class="featured-image-wrapper ' . $classes . '">'; $output .= '<div class="featured-image">'; $output .= '<div class="featured-image-inner">'; $output .= $image; $output .= '</div><!-- .featured-image-inner (end) -->'; $output .= '</div><!-- .featured-image (end) -->'; $output .= '</div><!-- .featured-image-wrapper (end) -->'; // Apply filters if allowed if ($allow_filters) { $output = apply_filters('themeblvd_post_thumbnail', $output, $location, $size, $link, $image); } // Return final output return $output; }