Example #1
0
 while (have_posts()) {
     the_post();
     global $post, $smof_data;
     $thumb = esc_html(get_post_thumbnail_id($post->ID));
     $post_title = esc_html(get_the_title($post->ID));
     $post_url = esc_url(get_permalink($post->ID));
     $url_video = esc_url(get_post_meta($post->ID, THEME_SLUG . 'video_portfolio', true));
     $proj_link = esc_url(get_post_meta($post->ID, THEME_SLUG . 'proj_link', true));
     if (strlen(trim($proj_link)) < 0) {
         $proj_link = $post_url;
     }
     if (strlen(trim($url_video)) > 0) {
         $rand_id = rand() . time();
         $slider_start_li = array('id' => $rand_id, 'alt' => $post_title, 'title' => $post_title);
         if (strstr($url_video, 'youtube.com') || strstr($url_video, 'youtu.be')) {
             $thumb_url = array(get_thumbnail_video_src($url_video, 850, 340));
             $item_class = "thumb-video youtube-fancy";
         }
         if (strstr($url_video, 'vimeo.com')) {
             $thumb_url = array(wp_parse_thumbnail_vimeo(wp_parse_vimeo_link($url_video), 850, 340));
             $item_class = "thumb-video vimeo-fancy";
         }
         if ($thumb) {
             $thumb_url = wp_get_attachment_image_src($thumb, 'full');
         }
         $light_box_url = $url_video;
     } else {
         $thumb_url = wp_get_attachment_image_src($thumb, 'full');
         $item_class = "thumb-image";
         $light_box_url = esc_url($thumb_url[0]);
     }
    function recent_works_function($atts, $content = false)
    {
        extract(shortcode_atts(array('count_items' => '10', 'show_items' => 4, 'gallery' => ''), $atts));
        wp_reset_query();
        $args = array('post_type' => 'portfolio', 'showposts' => $count_items);
        if (strlen($gallery) > 0) {
            $args = array('post_type' => 'portfolio', 'showposts' => $count_items, 'tax_query' => array(array('taxonomy' => 'gallery', 'field' => 'slug', 'terms' => $gallery)));
        }
        $num_count = count(query_posts($args));
        if (have_posts()) {
            $id_widget = 'recent-works-shortcode' . rand(0, 1000);
            ob_start();
            ?>
			
			<div id="<?php 
            echo $id_widget;
            ?>
" class="shortcode-recent-works flexslider">
				<div class="slider-div">
					<ul class="slides">
					<?php 
            $i = 0;
            while (have_posts()) {
                the_post();
                global $post;
                ?>
							<li class="item<?php 
                if ($i == 0) {
                    echo ' first';
                }
                if (++$i == $num_count) {
                    echo ' last';
                }
                ?>
">
								<?php 
                $thumb_arr = get_thumbnail(300, 170, '', get_the_title(), get_the_title());
                $thumb = $thumb_arr["fullpath"];
                $url_video = get_post_meta($post->ID, THEME_SLUG . 'video_portfolio', true);
                if (strlen(trim($url_video)) > 0) {
                    if (strstr($url_video, 'youtube.com') || strstr($url_video, 'youtu.be')) {
                        $thumburl = array(get_thumbnail_video_src($url_video, 500, 500));
                        $item_class = "thumb-video youtube-fancy";
                    }
                    if (strstr($url_video, 'vimeo.com')) {
                        $thumburl = array(wp_parse_thumbnail_vimeo(wp_parse_vimeo_link($url_video), 500, 500));
                        $item_class = "thumb-video vimeo-fancy";
                    }
                    $light_box_url = $url_video;
                } else {
                    $thumb = get_post_thumbnail_id($post->ID);
                    $thumburl = wp_get_attachment_image_src($thumb, 'full');
                    $item_class = "thumb-image";
                    $light_box_url = $thumburl[0];
                }
                ?>
								<div class="image <?php 
                echo $id_widget;
                ?>
">
									<a class="thumbnail" href="<?php 
                the_permalink();
                ?>
"><?php 
                echo print_thumbnail($thumburl[0], true, $post_title, 500, 330);
                ?>
</a>
									<div class="icons">
										<div>
											<a class="zoom-gallery fancybox" title="<?php 
                echo get_the_title();
                ?>
" rel="fancybox" href="<?php 
                echo $light_box_url;
                ?>
"></a>
											<a class="link-gallery " title="<?php 
                echo get_the_title();
                ?>
" href="<?php 
                echo get_permalink();
                ?>
"></a>
										</div>
									</div>	
								</div>
								<div class="detail<?php 
                if (!$thumb) {
                    echo ' noimage';
                }
                ?>
">
									<p class="title"><h4 class="heading-title"><a  class="wpt_title" href="<?php 
                echo get_permalink($post->ID);
                ?>
"><?php 
                echo get_the_title($post->ID);
                ?>
</a></h4></p>
									<span class="author-time"><span class="author"><?php 
                the_author();
                ?>
</span><b>/</b><span class="time"><?php 
                the_time('F d,Y');
                ?>
</span><b>/</b><span class="comment-number"><?php 
                comments_number('0 Comments', '1 Comment', '% Comments');
                ?>
</span></span>
								</div>							
							</li>
					<?php 
            }
            ?>
					</ul>
				</div>
			</div>
			<div id="<?php 
            echo $id_widget;
            ?>
_clone" style="display:none;" class="shortcode-recent-works flexslider">
			</div>
			
			<script type="text/javascript">
				jQuery(document).ready(function() {
					flex_carousel_slide('#<?php 
            echo $id_widget;
            ?>
',<?php 
            echo $show_items;
            ?>
);
				});
			</script>
			<?php 
            $ret_html = ob_get_contents();
            ob_end_clean();
            //ob_end_flush();
        }
        wp_reset_query();
        return $ret_html;
    }