forked from CherryFramework/CherryFramework
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilterable-portfolio-loop.php
More file actions
280 lines (241 loc) · 9.14 KB
/
Copy pathfilterable-portfolio-loop.php
File metadata and controls
280 lines (241 loc) · 9.14 KB
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
<?php // Isotope Portfolio Init ?>
<?php // Theme Options vars
$layout_mode = of_get_option('layout_mode');
?>
<script>
jQuery(document).ready(function($) {
var $container = $('#portfolio-grid'),
items_count = $(".portfolio_item").size();
$(window).load(function(){
var selector = window.location.hash.replace( /^#category/, '.term' );
if ( selector == "#all" ) {
selector = '';
change_hash(selector);
}
setColumnWidth();
$container.isotope({
itemSelector : '.portfolio_item',
hiddenClass : 'portfolio_hidden',
resizable : false,
transformsEnabled : true,
layoutMode: '<?php echo $layout_mode; ?>',
filter: selector
})
$('#filters .active').removeClass('active')
$('#filters li a[data-filter="'+selector+'"]').parent('li').addClass('active');
$(window).on("debouncedresize", function( event ) {
arrange();
});
});
function getNumColumns(){
var $folioWrapper = $('#portfolio-grid').data('cols');
if($folioWrapper == '2cols') {
var winWidth = $("#portfolio-grid").width(),
column = 2;
if (winWidth<380) column = 1;
return column;
}
else if ($folioWrapper == '3cols') {
var winWidth = $("#portfolio-grid").width(),
column = 3;
if (winWidth<380) column = 1;
else if(winWidth>=380 && winWidth<788) column = 2;
else if(winWidth>=788 && winWidth<1160) column = 3;
else if(winWidth>=1160) column = 3;
return column;
}
else if ($folioWrapper == '4cols') {
var winWidth = $("#portfolio-grid").width(),
column = 4;
if (winWidth<380) column = 1;
else if(winWidth>=380 && winWidth<788) column = 2;
else if(winWidth>=788 && winWidth<1160) column = 3;
else if(winWidth>=1160) column = 4;
return column;
}
}
function setColumnWidth(){
var columns = getNumColumns(),
containerWidth = $("#portfolio-grid").width(),
postWidth = containerWidth/columns;
postWidth = Math.floor(postWidth);
$(".portfolio_item").each(function(index){
$(this).css({"width":postWidth+"px"});
});
}
function arrange(){
setColumnWidth();
$container.isotope('reLayout');
}
// Filter projects
$('.filter a').click(function(){
var $this = $(this).parent('li');
// don't proceed if already active
if ( $this.hasClass('active') ) {
return false;
}
var $optionSet = $this.parents('.filter');
// change active class
$optionSet.find('.active').removeClass('active');
$this.addClass('active');
var selector = $(this).attr('data-filter'),
filter_selector = '';
if ( selector != 'all' ) {
filter_selector = selector;
}
$container.isotope({ filter: filter_selector });
change_hash(selector);
var hiddenItems = 0,
showenItems = 0;
$(".portfolio_item").each(function(){
if ( $(this).hasClass('portfolio_hidden') ) {
hiddenItems++;
};
});
showenItems = items_count - hiddenItems;
if ( ($(this).attr('data-count')) > showenItems ) {
$(".pagination__posts").css({"display" : "block"});
} else {
$(".pagination__posts").css({"display" : "none"});
}
return false;
});
function change_hash(hash){
hash = hash.replace( /^.term/, 'category' );
if ( hash.length == 0 ) {
hash = 'all';
}
window.location.href = '#'+hash;
$('.pagination a').each(function(){
var item = $(this),
href = item.attr('href'),
end_slice = href.indexOf('#')==-1 ? href.length : href.indexOf('#') ;
href = href.slice(0, end_slice);
item.attr({'href':href+'#'+hash})
})
}
});
</script>
<?php
$i = 1;
if ( have_posts() ) while ( have_posts() ) : the_post();
// post ID is different in a second language solution
if ( function_exists( 'icl_object_id' ) ) $post = get_post( icl_object_id( $post->ID, 'portfolio', true ) );
// Get categories
$portfolio_cats = wp_get_object_terms($post->ID, 'portfolio_category');
// Get tags
$portfolio_tags = !is_wp_error( wp_get_object_terms($post->ID, 'portfolio_tag')) ? wp_get_object_terms($post->ID, 'portfolio_tag') : array();
// Theme Options vars
$folio_filter = of_get_option('folio_filter');
$folio_title = of_get_option('folio_title');
$folio_btn = of_get_option('folio_btn');
$folio_excerpt = of_get_option('folio_excerpt');
$folio_excerpt_count = of_get_option('folio_excerpt_count');
$lightbox = (of_get_option('folio_lightbox') != '') ? of_get_option('folio_lightbox') : 'yes';
// Set size for image
$image_size = array(
'width' => 600,
'height' => 380
);
// Get img URL, resize & crop
$thumb = get_post_thumbnail_id();
$img_url = wp_get_attachment_url( $thumb,'full');
$image = aq_resize( $img_url, $image_size['width'], $image_size['height'], true );
//mediaType init
$mediaType = get_post_meta($post->ID, 'tz_portfolio_type', true);
?>
<li class="portfolio_item <?php foreach( $portfolio_cats as $portfolio_cat ) { echo ' term_id_' . $portfolio_cat->term_id; } ?> <?php foreach( $portfolio_tags as $portfolio_tag ) { echo ' term_id_' . $portfolio_tag->term_id; } ?>">
<div class="portfolio_item_holder">
<?php
if ($lightbox == "yes") :
if ($mediaType == 'Image')
$prettyType = 'prettyPhoto';
else
$prettyType = "prettyPhoto[gallery".$i."]";
$link_href = $img_url;
$link_rel = 'rel="'.$prettyType.'"';
$zoom_icon = '<span class="zoom-icon"></span>';
else :
$link_href = get_permalink($post->ID);
$link_rel = '';
unset($zoom_icon);
endif;
// in any for Video and Audio posts no lightbox
if ( ($mediaType == 'Video') || ($mediaType == 'Audio') ) {
$link_href = get_permalink($post->ID);
$link_rel = '';
unset($zoom_icon);
} ?>
<?php if (has_post_thumbnail()) { ?>
<figure class="thumbnail thumbnail__portfolio">
<a href="<?php echo esc_url( $link_href ); ?>" class="image-wrap" title="<?php echo esc_attr( get_the_title( $post->ID ) ); ?>" <?php echo $link_rel; ?>>
<img src="<?php echo $image ?>" alt="<?php the_title(); ?>" />
<?php if (isset($zoom_icon)) echo $zoom_icon; ?>
</a>
</figure><!--/.thumbnail__portfolio-->
<?php }
if ( ($mediaType == 'Slideshow') || ($mediaType == 'Grid Gallery') ) {
// get attachments
$thumbid = 0;
$thumbid = get_post_thumbnail_id($post->ID);
$images = get_children( array(
'orderby' => 'menu_order',
'order' => 'ASC',
'post_type' => 'attachment',
'post_parent' => $post->ID,
'post_mime_type' => 'image',
'post_status' => null,
'numberposts' => -1
) );
// output attachments
if ( $images ) {
$attachment_counter = 0;
foreach ( $images as $attachment_id => $attachment ) {
if ( ($attachment->ID == $thumbid) ) continue;
$image_attributes = wp_get_attachment_image_src( $attachment_id, 'full' ); // returns an array
$image = aq_resize( $image_attributes[0], $image_size['width'], $image_size['height'], true );
$image_title = $attachment->post_title;
if (!$attachment_counter && !has_post_thumbnail()) {
if ($lightbox == "yes") {
$link_href = $image_attributes[0];
} else {
$link_href = get_permalink($post->ID);
}
$figure_before = '<figure class="thumbnail thumbnail__portfolio">';
$figure_after = '</figure><!--/.thumbnail__portfolio-->';
$link_style = 'display:block';
$img_tag = '<img src="'. esc_url( $image ).'" alt="'. esc_attr( $image_title ).'" />';
} else {
$figure_before = '';
$figure_after = '';
$link_href = $image_attributes[0];
$link_style = 'display:none';
unset($img_tag);
unset($zoom_icon);
} ?>
<?php echo $figure_before; ?><a href="<?php echo esc_url( $link_href ); ?>" class="image-wrap" title="<?php the_title(); ?>" style="<?php echo $link_style; ?>" <?php echo $link_rel; ?>><?php if (isset($img_tag)) echo $img_tag; if (isset($zoom_icon)) echo $zoom_icon; ?></a><?php echo $figure_after; ?>
<?php $attachment_counter++;
}
}
} ?>
<div class="caption caption__portfolio">
<?php if($folio_title == "yes"){ ?>
<h3><a href="<?php the_permalink(); ?>"><?php $title = the_title('','',FALSE); echo mb_substr($title, 0, 40); ?></a></h3>
<?php } ?>
<?php if($folio_excerpt == "yes"){ ?>
<p class="excerpt">
<?php
$excerpt = get_the_excerpt();
echo wp_trim_words( $excerpt, $folio_excerpt_count );
?>
</p>
<?php } ?>
<?php if($folio_btn == "yes"){
$button_text = of_get_option('folio_button_text') ? apply_filters( 'cherry_text_translate', of_get_option('folio_button_text'), 'folio_button_text' ) : theme_locals("read_more") ;
?>
<p><a href="<?php the_permalink() ?>" class="btn btn-primary"><?php echo $button_text ?></a></p>
<?php } ?>
</div><!--/.caption__portfolio-->
</div><!--/.portfolio_item_holder-->
</li><!--/.portfolio_item-->
<?php $i++; endwhile; ?>