portfolio-item.php

Download Link
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
<?php
	// Print portfolio
	function print_portfolio($item_xml){
		$additional = '';
		$view_all_port = find_xml_value($item_xml, 'view-all-portfolio');
		if( !empty($view_all_port) && $view_all_port != 'None' ){
			global $gdl_admin_translator;	
			if( $gdl_admin_translator == 'enable' ){
				$translator_view = get_option(THEME_SHORT_NAME.'_translator_view_all_portfolio', 'View All Portfolio');
			}else{
				$translator_view = __('View All Portfolio','gdl_front_end');
			}		
		
			$additional = '<a href="' . get_permalink( get_page_by_title($view_all_port) );
			$additional = $additional . '" class="view-all-projects"><span>/ </span>';
			$additional = $additional . $translator_view . '</a>';
		}
		
		print_item_header( find_xml_value($item_xml, 'header'), $additional );

		global $paged, $gdl_element_id;
		
		if(empty($paged)){ $paged = (get_query_var('page')) ? get_query_var('page') : 1; }

		// get the portfolio meta value
		$num_fetch = find_xml_value($item_xml, 'num-fetch');
		$port_size = find_xml_value($item_xml, 'item-size');
		$show_title = (find_xml_value($item_xml, "show-title") == "Yes")? true: false;
		$show_tag = (find_xml_value($item_xml, "show-tag") == "Yes")? true: false;		
		
		$category = find_xml_value($item_xml, 'category', false);
		$category = ( $category == 'All' )? '': $category;
		
		$filter_cat = empty($_GET['filter'])? $category: $_GET['filter'];
		
		$order = find_xml_value($item_xml, 'order');
		$orderby = find_xml_value($item_xml, 'orderby');

		query_posts(array('post_type'=>'portfolio', 'paged'=>$paged, 'order'=>$order, 'orderby'=>$orderby,
			'portfolio-category'=>$filter_cat, 'posts_per_page'=>$num_fetch));

		// get the item class and size from array
		$portfolio_type = find_xml_value($item_xml, 'portfolio-type');
		if($portfolio_type == 'Portfolio'){
			print_normal_portfolio( $port_size, $show_title, $show_tag );
		}else if($portfolio_type == 'Filter Portfolio'){
			print_filter_portfolio( $port_size, $show_title, $show_tag, $category);
		}else if($portfolio_type == 'jQuery Filter Portfolio'){
			print_jquery_filter_portfolio( $port_size, $show_title, $show_tag, $category);
		}else if($portfolio_type == 'Carousel Portfolio'){
			print_carousel_portfolio( $port_size, $show_title, $show_tag );
		}		

		echo '<div class="clear"></div>';
		if( find_xml_value($item_xml, "pagination") == "Yes" ){	
			echo '<div class="portfolio-pagination">';
			pagination();
			echo '</div>';
		}
		
		$gdl_element_id++;
		wp_reset_query();
	}
	
	// Print portfolio thumbnail
	function print_portfolio_thumbnail( $post_id, $item_size ){
		global $gdl_element_id;
		
		$thumbnail_types = get_post_meta( $post_id, 'post-option-thumbnail-types', true);
		if( $thumbnail_types == "Image" ){
			$attribute = "";
			$thumbnail_id = get_post_thumbnail_id();
			$thumbnail = wp_get_attachment_image_src( $thumbnail_id , $item_size );
			$alt_text = get_post_meta($thumbnail_id , '_wp_attachment_image_alt', true);
			
			$image_type = get_post_meta( $post_id, 'post-option-featured-image-type', true);
			if( $image_type == "Link to Current Post" || empty($image_type) ){
				$hover_thumb = "hover-link";
				$permalink = get_permalink();
			}else if( $image_type == "Link to URL"){
				$hover_thumb = "hover-link";
				$attribute = ' target="_blank"';
				$permalink = __(get_post_meta( $post_id, 'post-option-featured-image-url', true ), 'gdl_front_end');
			}else if( $image_type == "Lightbox to Current Thumbnail" ){	
				$hover_thumb = "hover-zoom";
				$attribute = ' data-rel="fancybox" data-fancybox-group="gal' . $gdl_element_id . '" ';
				$permalink = wp_get_attachment_image_src( $thumbnail_id, 'full' );
				$permalink = $permalink[0];
			}else if( $image_type == "Lightbox to Picture" ){
				$hover_thumb = "hover-zoom";
				$attribute = ' data-rel="fancybox" data-fancybox-group="gal' . $gdl_element_id . '" ';
				$permalink = __(get_post_meta( $post_id, 'post-option-featured-image-url', true ), 'gdl_front_end');
			}else{
				$hover_thumb = "hover-video";
				$attribute = ' data-rel="fancybox" data-fancybox-type="iframe" ';
				$permalink = __(get_post_meta( $post_id, 'post-option-featured-image-url', true ), 'gdl_front_end');				
			}
			
			if( !empty($thumbnail[0]) ){
				echo '<div class="portfolio-media-wrapper gdl-image">';
				echo '<a class="hover-wrapper" href="' . $permalink . '" ' . $attribute . ' title="' . get_the_title() . '">';
				echo '<span class="portfolio-thumbnail-image-hover"></span>';
				echo '<span class="' . $hover_thumb . ' hover-icon"></span>';
				echo '</a>';
				echo '<img src="' . $thumbnail[0] .'" alt="'. $alt_text .'"/>';
				echo '</div>'; 				
			}
		}else if( $thumbnail_types == "Video" ){
			$video_link = get_post_meta( $post_id, 'post-option-thumbnail-video', true); 
			echo '<div class="portfolio-media-wrapper gdl-video">';
			echo get_video($video_link, gdl_get_width($item_size), gdl_get_height($item_size));
			echo '</div>';
		}else if ( $thumbnail_types == "Slider" ){
			$slider_xml = get_post_meta( $post_id, 'post-option-thumbnail-xml', true); 
			$slider_xml_dom = new DOMDocument();
			$slider_xml_dom->loadXML($slider_xml);
			echo '<div class="portfolio-media-wrapper gdl-slider">';
			echo print_flex_slider($slider_xml_dom->documentElement, $item_size);
			echo '</div>';			
		}else if ( $thumbnail_types == "HTML5 Video" ){
			$video = get_post_meta( $post_id, 'post-option-thumbnail-html5-video', true); 
			echo '<div class="portfolio-media-wrapper gdl-html5-video">';
			echo get_html5_video($video);
			echo '</div>';	// blog-media-wrapper		
		}		
	}
	
	// print the port thumbnail
	function print_single_port_thumbnail( $post_id, $item_size ){
		$thumbnail_types = get_post_meta( $post_id, 'post-option-inside-thumbnail-types', true);
		
		if( $thumbnail_types == "Image" || empty($thumbnail_types) ){
			$thumbnail_id = get_post_meta( $post_id, 'post-option-inside-thumbnial-image', true);
			$thumbnail = wp_get_attachment_image_src( $thumbnail_id , $item_size );
			$thumbnail_full = wp_get_attachment_image_src( $thumbnail_id , 'full' );
			$alt_text = get_post_meta($thumbnail_id , '_wp_attachment_image_alt', true);
			if( !empty($thumbnail) ){
				echo '<div class="port-media-wrapper gdl-image">';
				echo '<a href="' . $thumbnail_full[0] . '" data-rel="fancybox" title="' . get_the_title() . '">';
				echo '<img src="' . $thumbnail[0] .'" alt="'. $alt_text .'"/>';
				echo '</a>';
				echo '</div>'; // port-media-wrapper
			}
		}else if( $thumbnail_types == "Video" ){
			$video_link = get_post_meta( $post_id, 'post-option-inside-thumbnail-video', true);
			echo '<div class="port-media-wrapper gdl-video">';
			echo get_video($video_link, gdl_get_width($item_size), gdl_get_height($item_size));
			echo '</div>';	// port-media-wrapper
		}else if ( $thumbnail_types == "Slider" ){
			$slider_xml = get_post_meta( $post_id, 'post-option-inside-thumbnail-xml', true);
			$slider_xml_dom = new DOMDocument();
			$slider_xml_dom->loadXML($slider_xml);
			echo '<div class="port-media-wrapper gdl-slider">';
			echo print_flex_slider($slider_xml_dom->documentElement, $item_size);
			echo '</div>';	// port-media-wrapper
		}else if ( $thumbnail_types == "Stack Images" ){
			$slider_xml = get_post_meta( $post_id, 'post-option-inside-thumbnail-xml', true);
			$slider_xml_dom = new DOMDocument();
			$slider_xml_dom->loadXML($slider_xml);
			echo '<div class="port-media-wrapper gdl-stack-images">';
			echo print_stack_images($slider_xml_dom->documentElement, $item_size);
			echo '</div>';	// port-media-wrapper
		}else if ( $thumbnail_types == "HTML5 Video" ){
			$video = get_post_meta( $post_id, 'post-option-inside-thumbnail-html5-video', true); 
			echo '<div class="port-media-wrapper gdl-html5-video">';
			get_html5_video($video);
			echo '</div>';	// port-media-wrapper		
		}		
	}	
	
	// Print normal portfolio
	function print_normal_portfolio( $port_size = "1/4", $show_title = true, $show_tag = true ){
		global $port_div_size_num_class, $sidebar_type;
	
		$portfolio_row_size = 0;
		$item_size = $port_div_size_num_class[$port_size][$sidebar_type];		
		
		echo '<div class="portfolio-item-holder row">';
		while( have_posts() ){
			the_post();		
			
			print_item_size($port_size, 0.1, 'portfolio-item mb20');
			
			print_portfolio_thumbnail( get_the_ID(), $item_size );
			
			// portfolio context
			if( $show_title || $show_tag ){
				echo '<div class="portfolio-context">';
				if( $show_title ){
					echo '<h2 class="portfolio-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
				}
				if( $show_tag ){			
					$portfolio_tag = get_the_term_list( get_the_ID(), 'portfolio-tag', '', ', ', '' );
					echo '<div class="portfolio-tag">';
					echo $portfolio_tag;			
					echo '</div>';
				}
				echo '</div>'; // close portfolio context
			}
			echo '<div class="clear"></div>';
			echo '</div>'; // close print_item_size
		}
		echo '</div>'; // portfolio item holder
	}
	
	// Print filter portfolio
	function print_filter_portfolio( $port_size = "1/4", $show_title = true, $show_tag = true, $parent_category){
		global $port_div_size_num_class, $sidebar_type;
		global $gdl_admin_translator;	
		if( $gdl_admin_translator == 'enable' ){
			$translator_all = get_option(THEME_SHORT_NAME.'_translator_all', 'All');
		}else{
			$translator_all = __('All','gdl_front_end');
		}
		
		$item_size = $port_div_size_num_class[$port_size][$sidebar_type];
		$current_filter = empty($_GET['filter'])? 'All': $_GET['filter'];		
		$active = '';
		
		// filter portfolio button
		$category_lists = get_category_list('portfolio-category', $parent_category);
		echo '<ul class="portfolio-item-filter">';
		foreach($category_lists as $category){
			if( $category == 'All'){
				if( $current_filter == $category ) $active = 'active';
				echo '<li><a href="' . get_permalink() . '" class="gdl-button ' . $active . '">' . $translator_all . '</a></li>';
			}else{
				if( $current_filter == $category ) $active = 'active';
				$current_cat = get_term_by('slug', $category, 'portfolio-category');
				echo '<li><a href="' . add_query_arg(array('filter'=>$category)) . '" class="gdl-button ' . $active . '">'; 
				echo $current_cat->name;			
				echo '</a></li>';
			}
			$active = '';
		}
		echo "</ul>";
		echo '<div class="clear"></div>';

		
		// start portfolio looping
		echo '<div class="portfolio-item-holder row">';
		while( have_posts() ){
			the_post();		

			print_item_size($port_size, 0.1, 'portfolio-item mb20');
			
			print_portfolio_thumbnail( get_the_ID(), $item_size );
			
			// portfolio context
			if( $show_title || $show_tag ){
				echo '<div class="portfolio-context">';
				if( $show_title ){
					echo '<h2 class="portfolio-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
				}
				if( $show_tag ){			
					$portfolio_tag = get_the_term_list( get_the_ID(), 'portfolio-tag', '', ', ', '' );
					echo '<div class="portfolio-tag">';
					echo $portfolio_tag;			
					echo '</div>';
				}
				echo '</div>'; // close portfolio context
			}
			echo '<div class="clear"></div>';
			echo '</div>'; // close print_item_size - portfolio_item
		}
		echo '</div>'; // portfolio item holder 	
	}
	
	// Print jquery filter portfolio
	function print_jquery_filter_portfolio( $port_size = "1/4", $show_title = true, $show_tag = true, $parent_category){
		global $port_div_size_num_class, $sidebar_type;
		global $gdl_admin_translator;	
		if( $gdl_admin_translator == 'enable' ){
			$translator_all = get_option(THEME_SHORT_NAME.'_translator_all', 'All');
		}else{
			$translator_all = __('All','gdl_front_end');
		}
		
		$item_size = $port_div_size_num_class[$port_size][$sidebar_type];	

		// filter portfolio button
		$category_lists = get_category_list('portfolio-category', $parent_category);
		$category_check = array();
		foreach( $category_lists as $category ){ $category_check[$category] = false; }
		if( empty( $parent_category) ){ 
			$category_check = array('All'=>$translator_all); 
		}else{
			$first_category = get_term_by('slug', $parent_category, 'portfolio-category');
			$category_check[$parent_category] = $first_category->name; 
		}

		while( have_posts() ){
			the_post();
			$post_categories = get_the_terms( get_the_ID(), 'portfolio-category' );
			if(!empty($post_categories)){
				foreach( $post_categories as $category ){ 
					$category_check[$category->slug] = $category->name; 
				}
			}
		}
		$is_first = 'active';
		echo '<ul class="portfolio-item-filter">';
		foreach($category_lists as $category){
			if( empty($category_check[$category]) ) continue;
			if( $is_first ){ 
				$cat_name = 'All';
			}else{
				$cat_name = $category;
			}
			
			echo '<li><a href="#" class="gdl-button ' . $is_first . '" data-value="' . $cat_name . '">'; 
			echo $category_check[$category];
			echo '</a></li>';
			
			$is_first  = '';
		}
		echo "</ul>";
		echo '<div class="clear"></div>';

		
		// start portfolio looping
		rewind_posts();
		echo '<div class="portfolio-item-holder row">';
		while( have_posts() ){
			the_post();		
			
			$portfolio_slug = "";
			$post_categories = get_the_terms( get_the_ID(), 'portfolio-category' );
			if(!empty($post_categories)){
				foreach( $post_categories as $category ){ 
					$portfolio_slug = $portfolio_slug . $category->slug . ' '; 
				}
			}
			
			print_item_size($port_size, 0.1, 'portfolio-item mb20 ' . $portfolio_slug);
			
			print_portfolio_thumbnail( get_the_ID(), $item_size );
			
			// portfolio context
			if( $show_title || $show_tag ){
				echo '<div class="portfolio-context">';
				if( $show_title ){
					echo '<h2 class="portfolio-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
				}
				if( $show_tag ){			
					$portfolio_tag = get_the_term_list( get_the_ID(), 'portfolio-tag', '', ', ', '' );
					echo '<div class="portfolio-tag">';
					echo $portfolio_tag;			
					echo '</div>';
				}
				echo '</div>'; // close portfolio context
			}
			echo '<div class="clear"></div>';
			echo '</div>'; // close print_item_size - portfolio_item
		}
		echo '</div>'; // portfolio item holder 
	}
	
	// Print carousel portfolio
	function print_carousel_portfolio( $port_size = "1/4", $show_title = true, $show_tag = true ){
		global $port_div_size_num_class, $sidebar_type;
	
		$portfolio_row_size = 0;
		$item_size = $port_div_size_num_class[$port_size][$sidebar_type];
		echo '<div class="portfolio-carousel-wrapper">';

		echo '<div class="port-nav-wrapper">';
		echo '<a class="port-nav left" ></a>';
		echo '<a class="port-nav right" ></a>';
		echo '</div>'; // port-nav-wrapper		
		
		echo '<div class="portfolio-item-holder row" data-index="0">';
		while( have_posts() ){
			the_post();		
			
			print_item_size($port_size, 0.1, 'portfolio-item mb0');
			
			print_portfolio_thumbnail( get_the_ID(), $item_size );
			
			// portfolio context
			if( $show_title || $show_tag ){
				echo '<div class="portfolio-context">';
				if( $show_title ){
					echo '<h2 class="portfolio-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
				}
				if( $show_tag ){			
					$portfolio_tag = get_the_term_list( get_the_ID(), 'portfolio-tag', '', ', ', '' );
					echo '<div class="portfolio-tag">';
					echo $portfolio_tag;			
					echo '</div>';
				}
				echo '</div>'; // close portfolio context
			}
			echo '<div class="clear"></div>';
			echo '</div>'; // close print_item_size
		}
		echo '</div>'; // portfolio item holder
		
		// port nav
		echo '<div class="clear"></div>';
		echo '</div>'; // gdl-carousel-wrapper
	}	
	
	// Print nested page
	function print_page_item($item_xml){
		print_item_header( find_xml_value($item_xml, 'header') );

		global $paged, $gdl_element_id, $port_div_size_num_class, $sidebar_type;
		
		if(empty($paged)){ $paged = (get_query_var('page')) ? get_query_var('page') : 1; }
		
		// get the page meta value
		$port_size = find_xml_value($item_xml, 'item-size');
		$item_size = $port_div_size_num_class[$port_size][$sidebar_type];	
		
		$num_fetch = find_xml_value($item_xml, 'num-fetch');
		$num_excerpt = find_xml_value($item_xml, 'num-excerpt');		

		query_posts(array('post_type'=>'page', 'paged'=>$paged, 'orderby'=>'menu_order', 'order'=>'asc',
			'post_parent'=>get_the_ID(), 'posts_per_page'=>$num_fetch ));
		
		echo '<div class="portfolio-item-holder row">';
		while( have_posts() ){
			the_post();

			print_item_size($port_size, 0.1, 'portfolio-item mb20');
			
			$thumbnail_id = get_post_thumbnail_id();
			if( !empty($thumbnail_id) ){
				$thumbnail = wp_get_attachment_image_src( $thumbnail_id , $item_size );
				$alt_text = get_post_meta($thumbnail_id , '_wp_attachment_image_alt', true);
				
				echo '<div class="portfolio-media-wrapper gdl-image">';
				echo '<a class="hover-wrapper" href="' . get_permalink() . '" >';
				echo '<span class="portfolio-thumbnail-image-hover">';
				echo '<span class="hover-link"></span>';
				echo '</span>';
				echo '</a>';
				echo '<img src="' . $thumbnail[0] .'" alt="'. $alt_text .'"/>';
				echo '</div>'; //portfolio thumbnail image						
			}
			
			$show_title = (find_xml_value($item_xml, "show-title") == "Yes")? true: false;
			$show_excerpt = (find_xml_value($item_xml, "show-excerpt") == "Yes")? true: false;
			if( $show_title || $show_excerpt ){
				echo '<div class="page-context">';
				if( $show_title){
					echo '<h2 class="page-item-title"><a href="' . get_permalink() . '">' . get_the_title() . '</a></h2>';
				}
				if( $show_excerpt ){			
					echo '<div class="page-item-content">' . gdl_get_excerpt($num_excerpt) . '</div>';
				}
				echo '</div>'; // port-thumbnail-contxt
			}
			
			echo '<div class="clear"></div>';
			echo '</div>'; // close print_item_size

		}
		echo "</div>"; // portfolio-item-holder
		
		echo '<div class="clear"></div>';
		if( find_xml_value($item_xml, "pagination") == "Yes" ){	
			pagination();
		}		
		
		wp_reset_query();		
	}
?>