예제 #1
0
    function vcex_post_type_flexslider_shortcode($atts)
    {
        extract(shortcode_atts(array('unique_id' => '', 'post_types' => 'post', 'tax_query' => '', 'tax_query_taxonomy' => '', 'tax_query_terms' => '', 'posts_per_page' => '4', 'order' => 'DESC', 'orderby' => 'date', 'filter_content' => 'false', 'offset' => 0, 'animation' => 'slide', 'slideshow' => 'true', 'randomize' => 'false', 'direction' => 'horizontal', 'slideshow_speed' => '7000', 'animation_speed' => '600', 'control_nav' => 'true', 'direction_nav' => 'true', 'pause_on_hover' => 'true', 'smooth_height' => 'true', 'img_width' => '9999', 'img_height' => '9999', 'caption' => true, 'caption_location' => 'over-slider', 'control_thumbs' => 'false', 'title' => 'true', 'excerpt' => 'true', 'excerpt_length' => '40'), $atts));
        // Turn output buffer on
        ob_start();
        // Get global $post var
        global $post;
        // Post types
        $post_types = $post_types ? $post_types : 'post';
        $post_types = explode(',', $post_types);
        // Tax Query
        if ('' != $tax_query && '' != $tax_query_taxonomy && '' != $tax_query_terms) {
            $tax_query_terms = explode(',', $tax_query_terms);
            $tax_query = array(array('taxonomy' => $tax_query_taxonomy, 'field' => 'slug', 'terms' => $tax_query_terms));
        } else {
            $tax_query = '';
        }
        // Build new query
        $vcex_query = new WP_Query(array('post_type' => $post_types, 'posts_per_page' => $posts_per_page, 'offset' => $offset, 'order' => $order, 'orderby' => $orderby, 'filter_content' => $filter_content, 'meta_query' => array(array('key' => '_thumbnail_id')), 'no_found_rows' => true, 'tax_query' => $tax_query));
        //Output posts
        if ($vcex_query->posts) {
            // Output script for inline JS for the Visual composer front-end builder
            if (function_exists('vcex_front_end_slider_js')) {
                vcex_front_end_slider_js();
            }
            // Control Thumbnails
            if ('true' == $control_thumbs) {
                $control_nav = 'thumbnails';
            } else {
                $control_nav = $control_nav;
            }
            // Flexslider Data
            $flexslider_data = 'data-animation="' . $animation . '"';
            $flexslider_data .= ' data-slideshow="' . $slideshow . '"';
            $flexslider_data .= ' data-randomize="' . $randomize . '"';
            $flexslider_data .= ' data-direction="' . $direction . '"';
            $flexslider_data .= ' data-slideshow-speed="' . $slideshow_speed . '"';
            $flexslider_data .= ' data-animation-speed="' . $animation_speed . '"';
            $flexslider_data .= ' data-direction-nav="' . $direction_nav . '"';
            $flexslider_data .= ' data-pause="' . $pause_on_hover . '"';
            $flexslider_data .= ' data-smooth-height="' . $smooth_height . '"';
            $flexslider_data .= ' data-control-nav="' . $control_nav . '"';
            // Main Vars
            $unique_id = $unique_id ? ' id="' . $unique_id . '"' : NULL;
            $img_crop = $img_height == '9999' ? false : true;
            ?>

				<div class="vcex-flexslider-wrap clr vcex-img-flexslider vcex-posttypes-flexslider"<?php 
            echo $unique_id;
            ?>
>
					<div class="vcex-flexslider flexslider" <?php 
            echo $flexslider_data;
            ?>
>
						<ul class="slides">
							<?php 
            // Loop through posts
            foreach ($vcex_query->posts as $post) {
                setup_postdata($post);
                $img_url = wp_get_attachment_url(get_post_thumbnail_id());
                // Thumb Data attr
                if ('true' == $control_thumbs) {
                    $data_thumb = 'data-thumb="' . wpex_image_resize($img_url, 100, 100, true) . '"';
                } else {
                    $data_thumb = '';
                }
                ?>
								<li class="vcex-flexslider-slide slide" <?php 
                echo $data_thumb;
                ?>
>
									<div class="vcex-flexslider-entry-media">
										<?php 
                if (has_post_thumbnail()) {
                    $cropped_img = wpex_image_resize($img_url, intval($img_width), intval($img_height), $img_crop, 'array');
                    if ($cropped_img && is_array($cropped_img)) {
                        ?>
												<a href="<?php 
                        the_permalink();
                        ?>
" title="<?php 
                        the_title();
                        ?>
">
													<img src="<?php 
                        echo $cropped_img['url'];
                        ?>
" alt="<?php 
                        the_title();
                        ?>
" class="vcex-post-type-entry-img" height="<?php 
                        echo $cropped_img['height'];
                        ?>
" width="<?php 
                        echo $cropped_img['width'];
                        ?>
" />
												</a>
											<?php 
                    }
                    ?>
										<?php 
                }
                // WooComerce Price
                if (class_exists('Woocommerce') && 'product' == get_post_type()) {
                    ?>
											<div class="slider-woocommerce-price">
												<?php 
                    $product = get_product(get_the_ID());
                    echo $product->get_price_html();
                    ?>
											</div><!-- .slider-woocommerce-price -->
										<?php 
                }
                ?>
										<?php 
                if ('true' == $caption) {
                    ?>
											<div class="vcex-img-flexslider-caption clr <?php 
                    echo $caption_location;
                    ?>
">
												<?php 
                    // Display title
                    if ('true' == $title) {
                        ?>
													<div class="title clr">
														<a href="<?php 
                        the_permalink();
                        ?>
" title="<?php 
                        the_title();
                        ?>
"><?php 
                        the_title();
                        ?>
</a>
														<?php 
                        if ('staff' == get_post_type() && get_post_meta(get_the_ID(), 'wpex_staff_position', true)) {
                            ?>
															<div class="staff-position">
																<?php 
                            echo get_post_meta(get_the_ID(), 'wpex_staff_position', true);
                            ?>
															</div>
														<?php 
                        }
                        ?>
													</div>
												<?php 
                    }
                    // Display excerpt
                    if ('true' == $excerpt) {
                        ?>
													<div class="excerpt clr">
														<?php 
                        $excerpt_array = array('length' => intval($excerpt_length));
                        vcex_excerpt($excerpt_array);
                        ?>
													</div><!-- .excerpt -->
												<?php 
                    }
                    ?>
											</div><!-- .vcex-img-flexslider-caption -->
										<?php 
                }
                ?>
									</div><!-- .vcex-flexslider-entry-media -->
								</li><!-- .vcex-posttypes-slide -->
							<?php 
            }
            ?>
						</ul><!-- .slides -->
					</div><!-- .flexslider -->
				</div><!-- .vcex-posttypes-flexslider -->
				<!-- Be safe and clear the floats -->
				<div class="vcex-clear-floats"></div>

			<?php 
            // End has posts check
        }
        // Reset the WP query
        wp_reset_postdata();
        // Return outbut buffer
        return ob_get_clean();
    }
예제 #2
0
    function vcex_image_flexslider_shortcode($atts)
    {
        // Define shortcode params
        extract(shortcode_atts(array('unique_id' => '', 'image_ids' => '', 'animation' => 'slide', 'slideshow' => 'true', 'randomize' => 'false', 'direction' => 'horizontal', 'slideshow_speed' => '7000', 'animation_speed' => '600', 'control_nav' => 'true', 'direction_nav' => 'true', 'pause_on_hover' => 'true', 'smooth_height' => 'false', 'thumbnail_link' => 'lightbox', 'custom_links' => '', 'custom_links_target' => '_self', 'img_width' => '9999', 'img_height' => '9999', 'caption' => 'true', 'img_rendering' => '', 'control_thumbs' => 'false'), $atts));
        // Turn output buffer on
        ob_start();
        // Get Attachments
        $attachments = explode(",", $image_ids);
        $attachments = array_combine($attachments, $attachments);
        // Dummy images when no images are defined
        $dummy_images = NULL;
        if (empty($image_ids)) {
            $dummy_images = true;
            $attachments = array(WPEX_VCEX_DIR_URI . 'assets/images/dummy2.jpg', WPEX_VCEX_DIR_URI . 'assets/images/dummy3.jpg');
        }
        //Output images
        if ($attachments) {
            // Output script for inline JS for the Visual composer front-end builder
            if (function_exists('vcex_front_end_slider_js')) {
                vcex_front_end_slider_js();
            }
            // Set output var
            $output = '';
            // Control Thumbnails
            if ('true' == $control_thumbs) {
                $control_nav = 'thumbnails';
            } else {
                $control_nav = $control_nav;
            }
            // Flexslider Data
            $flexslider_data = 'data-animation="' . $animation . '"';
            $flexslider_data .= ' data-slideshow="' . $slideshow . '"';
            $flexslider_data .= ' data-randomize="' . $randomize . '"';
            $flexslider_data .= ' data-direction="' . $direction . '"';
            $flexslider_data .= ' data-slideshow-speed="' . $slideshow_speed . '"';
            $flexslider_data .= ' data-animation-speed="' . $animation_speed . '"';
            $flexslider_data .= ' data-direction-nav="' . $direction_nav . '"';
            $flexslider_data .= ' data-pause="' . $pause_on_hover . '"';
            $flexslider_data .= ' data-smooth-height="' . $smooth_height . '"';
            $flexslider_data .= ' data-control-nav="' . $control_nav . '"';
            // Custom Links
            if ($thumbnail_link == 'custom_link') {
                $custom_links = explode(',', $custom_links);
            }
            // Main Classes
            $classes = 'vcex-flexslider-wrap vcex-img-flexslider flexslider-container clr';
            if ('lightbox' == $thumbnail_link) {
                $classes .= ' lightbox-group';
            }
            // Unique ID
            $unique_id = $unique_id ? ' id="' . $unique_id . '"' : NULL;
            ?>

			<div class="<?php 
            echo $classes;
            ?>
"<?php 
            echo $unique_id;
            ?>
>
				<div class="vcex-flexslider flexslider" <?php 
            echo $flexslider_data;
            ?>
>
					<ul class="slides">
					<?php 
            // Loop through attachments
            $count = -1;
            foreach ($attachments 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 = esc_attr(get_post_field('post_excerpt', $attachment));
                // 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);
                    $crop = $img_height == '9999' ? false : true;
                    $attachment_img = wpex_image_resize($attachment_img, $img_width, $img_height, $crop);
                }
                // Image rendering
                if ($img_rendering) {
                    $img_rendering = ' vcex-image-rendering-' . $img_rendering;
                }
                // Image output
                $image_output = '<img src="' . $attachment_img . '" alt="' . $attachment_alt . '" />';
                // Thumb Data attr
                if ('true' == $control_thumbs) {
                    $data_thumb = 'data-thumb="' . wpex_image_resize($attachment_img_url, 100, 100, true) . '"';
                } else {
                    $data_thumb = '';
                }
                ?>
		
						<li class="vcex-flexslider-slide slide <?php 
                echo $img_rendering;
                ?>
" <?php 
                echo $data_thumb;
                ?>
>
							<div class="vcex-flexslider-entry-media">
								<?php 
                // Lightbox links
                if ('lightbox' == $thumbnail_link) {
                    ?>
									<a href="<?php 
                    echo $attachment_img_url;
                    ?>
" title="<?php 
                    echo $attachment_caption;
                    ?>
" class="vcex-flexslider-entry-img lightbox-group-item">
										<?php 
                    echo $image_output;
                    ?>
									</a>
								<?php 
                    // Custom links
                } elseif ('custom_link' == $thumbnail_link) {
                    $custom_link = !empty($custom_links[$count]) ? $custom_links[$count] : '#';
                    if ('#' == $custom_link) {
                        ?>
										<?php 
                        echo $image_output;
                        ?>
									<?php 
                    } else {
                        ?>
										<a href="<?php 
                        echo esc_url($custom_link);
                        ?>
" title="<?php 
                        echo $attachment_caption;
                        ?>
" class="vcex-flexslider-entry-img" target="<?php 
                        echo $custom_links_target;
                        ?>
">
											<?php 
                        echo $image_output;
                        ?>
										</a>
									<?php 
                    }
                } else {
                    // Plain Image
                    echo $image_output;
                }
                // Image Caption
                if ('true' == $caption && $attachment_caption) {
                    ?>
									<div class="vcex-img-flexslider-caption clr">
										<?php 
                    echo $attachment_caption;
                    ?>
									</div><!-- .vcex-flexslider-entry-caption -->
								<?php 
                }
                ?>
							</div><!-- .vcex-flexslider-entry-media -->
						</li>
					<?php 
            }
            ?>
					</ul>
				</div>
			</div>
		<div class="vcex-clear-floats"></div>
		<?php 
        }
        // End has posts check
        // Return outbut buffer
        return ob_get_clean();
    }