/
portfolio-helpers.php
144 lines (128 loc) · 4.2 KB
/
portfolio-helpers.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
<?php
/**
* @package Portfolio Press
*/
/**
* Overrides the default behavior of portfolio taxonomies to use the archive-portfolio template
* http://www.billerickson.net/reusing-wordpress-theme-files/
*
* @param string template path
*/
function portfoliopress_template_chooser( $template ) {
global $wp_query;
$portfolio = false;
// Check if the taxonomy query contains only image or gallery post formats
if ( is_category() || is_tag() || is_home() ) {
$portfolio = true;
if ( $wp_query->have_posts() ) :
while ( $wp_query->have_posts() ) : $wp_query->the_post();
$format = get_post_format();
if ( ( $format !=='image' ) && ( $format != 'gallery' ) ) {
$portfolio = false;
}
endwhile;
endif;
}
// Check if template should be displayed as archive-portfolio.php
if (
is_post_type_archive( 'portfolio' ) ||
is_tax( 'post_format', 'post-format-image' ) ||
is_tax( 'post_format', 'post-format-gallery' ) ||
is_tax( 'portfolio_category' ) ||
is_tax( 'portfolio_tag' )
) {
$portfolio = true;
}
// Use the archive-portfolio.php template
if ( $portfolio ) {
$wp_query->set( 'portfolio_view', true );
$template = get_query_template( 'archive-portfolio' );
}
return $template;
}
add_filter( 'template_include', 'portfoliopress_template_chooser' );
/**
* Adds a body class to archives that display as a portfolio view
*
* @param array classes applied to post
* @return array modified classes
*/
function portfoliopress_body_class( $classes ) {
global $post;
if (
is_page_template( 'templates/portfolio.php' ) ||
is_page_template( 'templates/full-width-portfolio.php' ) ||
is_page_template( 'templates/image-gallery-formats.php' ) ||
is_page_template( 'templates/full-width-image-gallery-formats.php' ) ||
get_query_var( 'portfolio_view' )
) {
$classes[] = 'portfolio-view';
if ( portfoliopress_get_option( 'portfolio_sidebar', false ) ) {
$classes[] = 'full-width-portfolio';
}
}
// Remove the term "templates" from the page template body class
// Primarily for backwards compatibility
if ( isset( $post) && (
is_page_template( 'templates/full-width-page.php' ) ||
is_page_template( 'templates/portfolio.php' ) ||
is_page_template( 'templates/full-width-portfolio.php' ) ||
is_page_template( 'templates/image-gallery-formats.php' ) ||
is_page_template( 'templates/full-width-image-gallery-formats.php' )
)
) {
foreach( $classes as $key => $value) {
if ( $value == 'page-template-templatesfull-width-page-php') {
$classes[$key] = 'page-template-full-width-page-php';
}
if ( $value == 'page-template-templatesportfolio-php') {
$classes[$key] = 'page-template-portfolio-php';
}
if ( $value == 'page-template-templatesfull-width-portfolio-php') {
$classes[$key] = 'page-template-full-width-portfolio-php';
}
if ( $value == 'page-template-templatesimage-gallery-formats-php') {
$classes[$key] = 'page-template-image-gallery-formats-php';
}
if ( $value == 'page-template-templatesfull-width-image-gallery-formats-php') {
$classes[$key] = 'page-template-full-width-image-gallery-formats-php';
}
}
}
if ( !portfoliopress_get_option( 'portfolio_sidebar', false ) ) {
if (
is_page_template( 'templates/full-width-portfolio.php' ) ||
is_page_template( 'templates/full-width-image-gallery-formats.php' )
) {
$classes[] = 'full-width-portfolio';
}
}
return $classes;
}
add_filter( 'body_class','portfoliopress_body_class' );
/**
* Helper function for displaying image
*/
function portfoliopress_display_image() {
// Don't display images on single post if the option is turned off
if ( is_single() && ! portfoliopress_get_option( 'portfolio_images', true ) ) {
return;
}
if ( ! post_password_required() && has_post_thumbnail() ) :
if ( ( 'image' == get_post_format() ) || 'portfolio' == get_post_type() ) { ?>
<div class="portfolio-image">
<?php if ( !is_single() ) { ?>
<a href="<?php the_permalink() ?>" rel="bookmark" class="thumb">
<?php } ?>
<?php if ( portfoliopress_get_option( 'layout' ) == 'layout-1col' ) {
the_post_thumbnail( 'portfolio-fullwidth' );
} else {
the_post_thumbnail( 'portfolio-large' );
} ?>
<?php if ( !is_single() ) { ?>
</a>
<?php } ?>
</div>
<?php }
endif;
}