/
loop-portfolio.php
228 lines (188 loc) · 7.32 KB
/
loop-portfolio.php
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
<?php
/**
* Loop - Portfolio
*
* This is a custom loop file, containing the looping logic for use in the "portfolio" page template,
* as well as the "portfolio-gallery" taxonomy archive screens. The custom query is only run on the page
* template, as we already have the data we need when on the taxonomy archive screens.
*
* @package WooFramework
* @subpackage Template
*/
global $woo_options;
global $more; $more = 0;
/* Setup parameters for this loop. */
/* Make sure we only run our custom query when using the page template, and not in a taxonomy. */
$thumb_width = 207;
$thumb_height = 212;
/* The Variables */
$settings = array(
'portfolio_enable_pagination' => 'false',
'portfolio_posts_per_page' => get_option( 'posts_per_page' ),
'portfolio_thumb_width' => '',
'portfolio_thumb_height' => '',
'portfolio_excludenav' => ''
);
$settings = woo_get_dynamic_values( $settings );
/* Setup array of booleans to make filtering of this setting easier. */
$settings_toggle = array( 'true' => true, 'false' => false );
/* Add toggle for the pagination vs portfolio filter bar. */
$toggle_pagination = apply_filters( 'woo_portfolio_toggle_pagination', $settings_toggle[$settings['portfolio_enable_pagination']] ); // Default: false
$filtering_css_class = 'has-filtering';
if ( $toggle_pagination == true || is_tax( 'portfolio-gallery' ) ) {
$filtering_css_class = 'no-filtering';
}
/* Make sure our thumbnail dimensions come through from the theme options. */
if ( isset( $settings['portfolio_thumb_width'] ) && ( $settings['portfolio_thumb_width'] != '' ) ) {
$thumb_width = $settings['portfolio_thumb_width'];
}
if ( isset( $settings['portfolio_thumb_height'] ) && ( $settings['portfolio_thumb_height'] != '' ) ) {
$thumb_height = $settings['portfolio_thumb_height'];
}
/* Setup portfolio galleries navigation. */
$galleries = array();
$galleries = get_terms( 'portfolio-gallery' );
$exclude_str = '';
$to_exclude = array();
if ( isset( $settings['portfolio_excludenav'] ) && ( $settings['portfolio_excludenav'] != '' ) ) {
$exclude_str = $settings['portfolio_excludenav'];
}
// Allow child themes/plugins to filter here.
$exclude_str = apply_filters( 'woo_portfolio_gallery_exclude', $exclude_str );
/* Optionally exclude navigation items. */
if ( $exclude_str != '' ) {
$to_exclude = explode( ',', $exclude_str );
if ( is_array( $to_exclude ) ) {
foreach ( $to_exclude as $k => $v ) {
$to_exclude[$k] = str_replace( ' ', '', $v );
}
/* Remove the galleries to be excluded. */
foreach ( $galleries as $k => $v ) {
if ( in_array( $v->slug, $to_exclude ) ) {
unset( $galleries[$k] );
}
}
}
}
/* Save the current state before we perform a new query. */
$screen_type = 'page';
$archive_title = '';
$current = 'all';
if ( is_post_type_archive() ) { $screen_type = 'post-type-archive'; }
if ( is_tax() ) {
$screen_type = 'taxonomy';
$archive_title = '';
$obj = get_queried_object();
if ( isset( $obj->name ) ) {
$archive_title = $obj->name;
$current = $obj->term_id;
}
}
if ( ! is_tax() ) {
if ( get_query_var( 'page' ) > 1) { $paged = get_query_var( 'page' ); } elseif ( get_query_var( 'paged' ) > 1) { $paged = get_query_var( 'paged' ); } else { $paged = 1; }
$query_args = array(
'post_type' => 'portfolio',
'paged' => $paged,
'posts_per_page' => -1
);
if ( $toggle_pagination == true ) {
$query_args['posts_per_page'] = $settings['portfolio_posts_per_page'];
}
/* If we have galleries, make sure we only get items from those galleries. */
if ( count( $galleries ) > 0 ) {
$gallery_slugs = array();
foreach ( $galleries as $g ) { $gallery_slugs[] = $g->slug; }
$query_args['tax_query'] = array(
array(
'taxonomy' => 'portfolio-gallery',
'field' => 'slug',
'terms' => $gallery_slugs
)
);
}
/* The Query. */
query_posts( $query_args );
} // End IF Statement ( is_tax() )
/* The Loop. */
if ( have_posts() ) : $count = 0; ?>
<header class="<?php echo $filtering_css_class; ?> section-title portfolio">
<h1 class="fix">
<?php
if ( $screen_type == 'page' ) { ?><?php the_title(); ?><?php }
elseif ( $screen_type == 'post-type-archive' ) { echo apply_filters( 'woo_portfolio_type_archive_title', __( 'Portfolio', 'woothemes' ) ) ; }
elseif ( $screen_type == 'taxonomy' ) { echo stripslashes( $archive_title ); }
?>
</h1>
<?php if ($woo_options['woo_portfolio_section_message'] && $woo_options['woo_portfolio_section_message'] != ''): ?>
<p><span><?php echo stripslashes( esc_attr( $woo_options['woo_portfolio_section_message'] ) ); ?></span></p>
<?php endif; ?>
<?php
/* Display the gallery navigation (from theme-functions.php). */
woo_portfolio_navigation( $galleries, array( 'current' => $current ), $toggle_pagination );
?>
</header>
<div id="portfolio" class="portfolio-items type-page fix">
<?php echo term_description(); ?>
<?php
while ( have_posts() ) : the_post(); $count++;
/* Get the settings for this portfolio item. */
$settings = woo_portfolio_item_settings( $post->ID );
/* If the theme option is set to link to the single portfolio item, adjust the $settings. */
if ( isset( $woo_options['woo_portfolio_linkto'] ) && ( $woo_options['woo_portfolio_linkto'] == 'post' ) ) {
$settings['large'] = get_permalink( $post->ID );
$settings['rel'] = '';
}
// Check for custom URL on item
$custom_url = get_post_meta( $post->ID, '_portfolio_url', true );
if ( $custom_url != '' )
$settings['large'] = $custom_url;
?>
<article id="portfolio-item-id-<?php the_ID(); ?>" <?php post_class( 'portfolio-item' ); ?>>
<?php
/* Setup image for display and for checks, to avoid doing multiple queries. */
$image = woo_image( 'width=207&height=212&link=img&return=true&class=thumbnail' );
$image_src = woo_image( 'width=207&height=212&link=url&return=true&class=thumbnail' );
if ( !$image )
$image = '<img src="' . get_template_directory_uri() . '/images/temp-portfolio.png" alt="" />';
?>
<a <?php echo $settings['rel']; ?> title="<?php echo $settings['caption']; ?>" href="<?php echo $settings['large']; ?>" class="item drop-shadow curved curved-hz-1">
<?php echo $image; ?>
<span class="mask">
</span>
</a>
<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
<?php
//setup terms
$tag_list = get_the_term_list( $post->ID, 'portfolio-gallery', '' , ', ' , '' );
$tag_list = strip_tags($tag_list);
?>
<p class="category"><?php echo $tag_list; ?></p>
<?php
// Output image gallery for lightbox
if ( ! empty( $settings['gallery'] ) ) {
foreach ( array_slice( $settings['gallery'], 1 ) as $img => $attachment ) {
if ( $attachment['url'] != $image_src ) {
echo '<a ' . $settings['rel'] . ' title="' . $attachment['caption'] . '" href="' . $attachment['url'] . '" class="gallery-image"></a>' . "\n";
}
}
}
?>
</article>
<?php
endwhile;
?>
</div><!--/.portfolio-items-->
<?php
if ( $toggle_pagination == true ) {
woo_pagenav();
}
?>
<?php else : ?>
<div <?php post_class(); ?>>
<p><?php _e( 'Sorry, no posts matched your criteria.', 'woothemes' ); ?></p>
</div><!-- .post -->
<?php
endif;
rewind_posts();
wp_reset_query();
?>