function vcex_portfolio_carousel_shortcode($atts) { extract(shortcode_atts(array('unique_id' => '', 'classes' => '', 'style' => 'default', 'term_slug' => '', 'include_categories' => '', 'exclude_categories' => '', 'count' => '8', 'center' => 'false', 'timeout_duration' => '5000', 'items' => '4', 'items_margin' => '15', 'infinite_loop' => 'true', 'items_scroll' => '1', 'auto_play' => 'false', 'arrows' => 'true', 'order' => 'DESC', 'orderby' => 'date', 'orderby_meta_key' => '', 'thumbnail_link' => '', 'img_width' => '9999', 'img_height' => '9999', 'title' => 'true', 'excerpt' => 'true', 'excerpt_length' => '30', 'custom_excerpt_trim' => 'true', 'filter_content' => 'false', 'offset' => 0, 'taxonomy' => '', 'terms' => '', 'img_hover_style' => '', 'img_rendering' => '', 'overlay_style' => '', 'content_background' => '', 'content_heading_margin' => '', 'content_heading_weight' => '', 'content_heading_transform' => '', 'content_margin' => '', 'content_font_size' => '', 'content_padding' => '', 'content_border' => '', 'content_color' => '', 'content_opacity' => '', 'content_heading_color' => '', 'content_heading_size' => '', 'content_alignment' => '', 'tablet_items' => '3', 'mobile_landscape_items' => '2', 'mobile_portrait_items' => '1'), $atts)); // Turn output buffer on ob_start(); // Global post global $post; // Include categories $include_categories = '' != $include_categories ? $include_categories : $term_slug; $include_categories = 'all' == $include_categories ? '' : $include_categories; $filter_cats_include = ''; if ($include_categories) { $include_categories = explode(',', $include_categories); $filter_cats_include = array(); foreach ($include_categories as $key) { $key = get_term_by('slug', $key, 'portfolio_category'); $filter_cats_include[] = $key->term_id; } } // Exclude categories $filter_cats_exclude = ''; if ($exclude_categories) { $exclude_categories = explode(',', $exclude_categories); if (!empty($exclude_categories) && is_array($exclude_categories)) { $filter_cats_exclude = array(); foreach ($exclude_categories as $key) { $key = get_term_by('slug', $key, 'portfolio_category'); $filter_cats_exclude[] = $key->term_id; } $exclude_categories = array('taxonomy' => 'portfolio_category', 'field' => 'slug', 'terms' => $exclude_categories, 'operator' => 'NOT IN'); } else { $exclude_categories = ''; } } // Start Tax Query if (!empty($include_categories) && is_array($include_categories)) { $include_categories = array('taxonomy' => 'portfolio_category', 'field' => 'slug', 'terms' => $include_categories, 'operator' => 'IN'); } else { $include_categories = ''; } // Meta key for orderby if ($orderby_meta_key && ('meta_value_num' == $orderby || 'meta_value' == $orderby)) { $meta_key = $orderby_meta_key; } else { $meta_key = NULL; } // The Query $wpex_query = new WP_Query(array('post_type' => 'portfolio', 'posts_per_page' => $count, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby, 'filter_content' => $filter_content, 'no_found_rows' => true, 'meta_key' => $meta_key, 'tax_query' => array('relation' => 'AND', $include_categories, $exclude_categories))); //Output posts if ($wpex_query->posts) { // Output js for front-end editor vcex_front_end_carousel_js(); // Give caroufredsel a unique name $rand_num = rand(1, 100); $unique_carousel_id = 'carousel-' . $rand_num; // Prevent auto play in visual composer if (wpex_is_front_end_composer()) { $auto_play = 'false'; } // Overlay Style if (empty($overlay_style)) { $overlay_style = 'none'; } else { $overlay_style = $overlay_style; } // Item Margin if ('no-margins' == $style) { $items_margin = '0'; } // Items to scroll fallback for old setting if ('page' == $items_scroll) { $items_scroll = $items; } // Unique ID if ($unique_id) { $unique_id = ' id="' . $unique_id . '"'; } // Main Classes $main_classes = 'wpex-carousel wpex-carousel-portfolio clr owl-carousel'; if ($style) { $main_classes .= ' wpex-carousel-' . $style; } if ($classes) { $main_classes .= ' ' . $classes; } // Entry media classes $media_classes = 'wpex-carousel-entry-media clr'; if ($img_hover_style) { $media_classes .= ' vcex-img-hover-parent vcex-img-hover-' . $img_hover_style; } if ($img_rendering) { $media_classes .= ' vcex-image-rendering-' . $img_rendering; } if ($overlay_style) { $media_classes .= ' ' . wpex_overlay_classname($overlay_style); } // Content Design $content_style = ''; if ($content_background) { $content_style .= 'background:' . $content_background . ';'; } if ($content_padding) { $content_style .= 'padding:' . $content_padding . ';'; } if ($content_margin) { $content_style .= 'margin:' . $content_margin . ';'; } if ($content_border) { $content_style .= 'border:' . $content_border . ';'; } if ($content_font_size) { $content_style .= 'font-size:' . $content_font_size . ';'; } if ($content_color) { $content_style .= 'color:' . $content_color . ';'; } if ($content_opacity) { $content_style .= 'opacity:' . $content_opacity . ';'; } if ($content_alignment) { $content_style .= 'text-align:' . $content_alignment . ';'; } if ($content_style) { $content_style = ' style="' . $content_style . '"'; } // Title design $heading_style = ''; if ($content_heading_margin) { $heading_style .= 'margin: ' . $content_heading_margin . ';'; } if ($content_heading_transform) { $heading_style .= 'text-transform: ' . $content_heading_transform . ';'; } if ($content_heading_weight) { $heading_style .= 'font-weight: ' . $content_heading_weight . ';'; } if ($content_heading_size) { $heading_style .= 'font-size: ' . $content_heading_size . ';'; } if ($heading_style) { $heading_style = ' style="' . $heading_style . '"'; } // Heading color if ($content_heading_color) { $content_heading_color = ' style="color: ' . $content_heading_color . ';"'; } ?> <div class="<?php echo $main_classes; ?> "<?php echo $unique_id; ?> data-items="<?php echo $items; ?> " data-slideby="<?php echo $items_scroll; ?> " data-nav="<?php echo $arrows; ?> " data-autoplay="<?php echo $auto_play; ?> " data-loop="<?php echo $infinite_loop; ?> " data-autoplay-timeout="<?php echo $timeout_duration; ?> " data-center="<?php echo $center; ?> " data-margin="<?php echo intval($items_margin); ?> " data-items-tablet="<?php echo $tablet_items; ?> " data-items-mobile-landscape="<?php echo $mobile_landscape_items; ?> " data-items-mobile-portrait="<?php echo $mobile_portrait_items; ?> "> <?php // Loop through posts foreach ($wpex_query->posts as $post) { setup_postdata($post); // Post VARS $postid = $post->ID; $featured_img_url = wp_get_attachment_url(get_post_thumbnail_id($postid)); $permalink = get_permalink($postid); $post_title = esc_attr(the_title_attribute('echo=0')); // Crop featured images if necessary if ('9999' == $img_height) { $img_crop = false; } else { $img_crop = true; } $featured_img = wpex_image_resize($featured_img_url, $img_width, $img_height, $img_crop, 'array'); ?> <div class="wpex-carousel-slide"> <?php // Media Wrap if (has_post_thumbnail()) { ?> <div class="<?php echo $media_classes; ?> "> <?php // No links if ('none' == $thumbnail_link) { ?> <img src="<?php echo $featured_img['url']; ?> " alt="<?php echo $post_title; ?> " width="<?php echo $featured_img['width']; ?> " height="<?php echo $featured_img['height']; ?> " /> <?php } elseif ('lightbox' == $thumbnail_link) { ?> <a href="<?php echo $featured_img_url; ?> " title="<?php echo $post_title; ?> " class="wpex-carousel-entry-img wpex-lightbox"> <img src="<?php echo $featured_img['url']; ?> " alt="<?php echo $post_title; ?> " width="<?php echo $featured_img['width']; ?> " height="<?php echo $featured_img['height']; ?> " /> <?php } else { ?> <a href="<?php echo $permalink; ?> " title="<?php echo $post_title; ?> " class="wpex-carousel-entry-img"> <img src="<?php echo $featured_img['url']; ?> " alt="<?php echo $post_title; ?> " width="<?php echo $featured_img['width']; ?> " height="<?php echo $featured_img['height']; ?> " /> <?php } ?> <?php // Overlay & close link if ('none' != $thumbnail_link) { // Inner Overlay if ($overlay_style) { wpex_overlay('inside_link', $overlay_style); } // Close link echo '</a><!-- .wpex-carousel-entry-img -->'; // Outside Overlay if ($overlay_style) { wpex_overlay('outside_link', $overlay_style); } } ?> </div><!-- .wpex-carousel-entry-media --> <?php } ?> <?php // Title if ('true' == $title || 'true' == $excerpt) { ?> <div class="wpex-carousel-entry-details clr"<?php echo $content_style; ?> > <?php // Title if ('true' == $title && $post_title) { ?> <div class="wpex-carousel-entry-title"<?php echo $heading_style; ?> > <a href="<?php echo $permalink; ?> " title="<?php echo $post_title; ?> "<?php echo $content_heading_color; ?> ><?php echo $post_title; ?> </a> </div> <?php } // Excerpt if ('true' == $excerpt) { if ('true' == $custom_excerpt_trim) { $custom_excerpt_trim = true; } else { $custom_excerpt_trim = false; } $excerpt_array = array('length' => intval($excerpt_length), 'readmore' => false, 'trim_custom_excerpts' => $custom_excerpt_trim); // Generate excerpt $get_excerpt = vcex_get_excerpt($excerpt_array); if ($get_excerpt) { ?> <div class="wpex-carousel-entry-excerpt clr"> <?php echo $get_excerpt; ?> </div><!-- .wpex-carousel-entry-excerpt --> <?php } ?> <?php } ?> </div><!-- .wpex-carousel-entry-details --> <?php } ?> </div><!-- .wpex-carousel-slide --> <?php // End foreach loop } ?> </div><!-- .wpex-carousel --> <?php } // End has posts check // Set things back to normal wp_reset_postdata(); // Return outbut buffer return ob_get_clean(); }
function vcex_image_carousel_shortcode($atts) { // Define shortcode params extract(shortcode_atts(array('unique_id' => '', 'classes' => '', 'style' => '', 'image_ids' => '', 'center' => 'false', 'timeout_duration' => '5000', 'items' => '4', 'items_margin' => '15', 'infinite_loop' => 'true', 'items_scroll' => '1', 'auto_play' => 'false', 'arrows' => 'true', 'thumbnail_link' => '', 'custom_links' => '', 'custom_links_target' => '', 'img_width' => '9999', 'img_height' => '9999', 'title' => 'false', 'title_type' => '', 'img_filter' => '', 'rounded_image' => '', 'img_hover_style' => '', 'img_rendering' => '', 'caption' => 'false', 'content_background' => '', 'content_heading_margin' => '', 'content_heading_weight' => '', 'content_heading_transform' => '', 'content_margin' => '', 'content_font_size' => '', 'content_padding' => '', 'content_border' => '', 'content_color' => '', 'content_opacity' => '', 'content_heading_color' => '', 'content_heading_size' => '', 'content_alignment' => '', 'tablet_items' => '3', 'mobile_landscape_items' => '2', 'mobile_portrait_items' => '1'), $atts)); // Turn output buffer on ob_start(); // Get Attachments $images = explode(',', $image_ids); $images = array_combine($images, $images); // Dummy Images $dummy_images = NULL; if (empty($image_ids)) { $dummy_images = true; $images = array(WPEX_VCEX_DIR_URI . 'assets/images/dummy1.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy2.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy3.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy4.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy5.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy6.jpg'); } // Classes $img_classes = array(); if ($rounded_image == 'yes') { $img_classes[] = 'vcex-rounded-images'; } if ($img_filter) { $img_classes[] = 'vcex-' . $img_filter; } if ($img_hover_style) { $img_classes[] = ' vcex-img-hover-parent vcex-img-hover-' . $img_hover_style; } $img_classes = implode(' ', $img_classes); // Custom Links if ($thumbnail_link == 'custom_link') { $custom_links = explode(',', $custom_links); } // Display carousel if there are images if ($images) { // Output js for front-end editor vcex_front_end_carousel_js(); // Give caroufredsel a unique name $rand_num = rand(1, 100); $unique_carousel_id = 'carousel-' . $rand_num; // Prevent auto play in visual composer if (wpex_is_front_end_composer()) { $auto_play = 'false'; } // Item Margin if ('no-margins' == $style) { $items_margin = '0'; } // Items to scroll fallback for old setting if ('page' == $items_scroll) { $items_scroll = $items; } // Unique ID if ($unique_id) { $unique_id = ' id="' . $unique_id . '"'; } // Main Classes $add_classes = 'wpex-carousel wpex-carousel-images clr owl-carousel'; if ($style) { $add_classes .= ' ' . $style; } if ($img_rendering) { $add_classes = ' vcex-image-rendering-' . $img_rendering; } if ($classes) { $add_classes .= ' ' . $classes; } ?> <div class="<?php echo $add_classes; ?> "<?php echo $unique_id; ?> data-items="<?php echo $items; ?> " data-slideby="<?php echo $items_scroll; ?> " data-nav="<?php echo $arrows; ?> " data-autoplay="<?php echo $auto_play; ?> " data-loop="<?php echo $infinite_loop; ?> " data-autoplay-timeout="<?php echo $timeout_duration; ?> " data-center="<?php echo $center; ?> " data-margin="<?php echo intval($items_margin); ?> " data-items-tablet="<?php echo $tablet_items; ?> " data-items-mobile-landscape="<?php echo $mobile_landscape_items; ?> " data-items-mobile-portrait="<?php echo $mobile_portrait_items; ?> "> <?php // Loop through images $count = -1; foreach ($images as $attachment) { $count++; // Attachment VARS $attachment_link = get_post_meta($attachment, '_wp_attachment_url', true); $attachment_img_url = wp_get_attachment_url($attachment); $attachment_alt = strip_tags(get_post_meta($attachment, '_wp_attachment_image_alt', true)); $attachment_caption = get_post_field('post_excerpt', $attachment); $attachment_title = get_the_title($attachment); if ('alt' == $title_type) { $attachment_title = $attachment_alt; } // Get and crop image if needed if ($dummy_images) { $attachment_img = $attachment; } else { $attachment_img = wp_get_attachment_url($attachment); $img_width = intval($img_width); $img_height = intval($img_height); if ('9999' == $img_height) { $crop = false; } else { $crop = true; } $attachment_img = wpex_image_resize($attachment_img, $img_width, $img_height, $crop); } // Image output $image_output = '<img src="' . $attachment_img . '" alt="' . $attachment_alt . '" />'; ?> <div class="wpex-carousel-slide"> <div class="wpex-carousel-entry-media clr <?php echo $img_classes; ?> "> <?php // Lightbox if ('lightbox' == $thumbnail_link) { ?> <a href="<?php echo $attachment_img_url; ?> " title="<?php echo $attachment_alt; ?> " class="wpex-carousel-entry-img wpex-lightbox"> <?php echo $image_output; ?> </a><!-- .wpex-carousel-entry-img --> <?php } elseif ('custom_link' == $thumbnail_link) { $custom_link = !empty($custom_links[$count]) ? $custom_links[$count] : '#'; if ($custom_link == '#') { echo $image_output; } else { ?> <a href="<?php echo esc_url($custom_link); ?> " title="<?php echo $attachment_alt; ?> " class="wpex-carousel-entry-img" target="<?php echo $custom_links_target; ?> "> <?php echo $image_output; ?> </a> <?php } } else { echo $image_output; } ?> </div><!-- .wpex-carousel-entry-media --> <?php // Open details if ('yes' == $title || 'yes' == $caption) { if ($attachment_title || $attachment_caption) { // Content Design $content_style = ''; if ($content_background) { $content_style .= 'background:' . $content_background . ';'; } if ($content_padding) { $content_style .= 'padding:' . $content_padding . ';'; } if ($content_margin) { $content_style .= 'margin:' . $content_margin . ';'; } if ($content_border) { $content_style .= 'border:' . $content_border . ';'; } if ($content_font_size) { $content_style .= 'font-size:' . $content_font_size . ';'; } if ($content_color) { $content_style .= 'color:' . $content_color . ';'; } if ($content_opacity) { $content_style .= 'opacity:' . $content_opacity . ';'; } if ($content_alignment) { $content_style .= 'text-align:' . $content_alignment . ';'; } if ($content_style) { $content_style = ' style="' . $content_style . '"'; } ?> <div class="wpex-carousel-entry-details clr"<?php echo $content_style; ?> > <?php } // Display title if ('yes' == $title && $attachment_title) { // Title design $heading_style = ''; if ($content_heading_margin) { $heading_style .= 'margin: ' . $content_heading_margin . ';'; } if ($content_heading_transform) { $heading_style .= 'text-transform: ' . $content_heading_transform . ';'; } if ($content_heading_weight) { $heading_style .= 'font-weight: ' . $content_heading_weight . ';'; } if ($content_heading_size) { $heading_style .= 'font-size: ' . $content_heading_size . ';'; } if ($content_heading_color) { $heading_style .= 'color: ' . $content_heading_color . ';'; } if ($heading_style) { $heading_style = ' style="' . $heading_style . '"'; } ?> <div class="wpex-carousel-entry-title"<?php echo $heading_style; ?> ><?php echo $attachment_title; ?> </div> <?php } // Display caption if ('yes' == $caption && $attachment_caption) { ?> <div class="wpex-carousel-entry-excerpt"><?php echo $attachment_caption; ?> </div> <?php } // Close details if ('yes' == $title || 'yes' == $caption) { if ($attachment_title || $attachment_caption) { ?> </div> <?php } } } ?> </div><!-- .wpex-carousel-slide --> <?php // End foreach loop } ?> </div><!-- .wpex-carousel --> <?php } // End has images check // Return outbut buffer return ob_get_clean(); }