1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/** |
3
|
|
|
* LSX Projects Main Class |
4
|
|
|
* |
5
|
|
|
* @package LSX Projects |
6
|
|
|
* @author LightSpeed |
7
|
|
|
* @license GPL3 |
8
|
|
|
* @link |
9
|
|
|
* @copyright 2016 LightSpeed |
10
|
|
|
*/ |
11
|
|
|
class LSX_Projects { |
12
|
|
|
|
13
|
|
|
public $columns, $responsive, $options; |
|
|
|
|
14
|
|
|
|
15
|
|
|
public function __construct() { |
|
|
|
|
16
|
|
|
$this->options = projects_get_options(); |
17
|
|
|
|
18
|
|
|
add_filter( 'lsx_banner_allowed_post_types', array( $this, 'lsx_banner_allowed_post_types' ) ); |
19
|
|
|
add_filter( 'lsx_banner_allowed_taxonomies', array( $this, 'lsx_banner_allowed_taxonomies' ) ); |
20
|
|
|
} |
|
|
|
|
21
|
|
|
|
22
|
|
|
/** |
|
|
|
|
23
|
|
|
* Enable project custom post type on LSX Banners. |
24
|
|
|
*/ |
25
|
|
|
public function lsx_banner_allowed_post_types( $post_types ) { |
26
|
|
|
$post_types[] = 'project'; |
27
|
|
|
return $post_types; |
28
|
|
|
} |
|
|
|
|
29
|
|
|
|
30
|
|
|
/** |
|
|
|
|
31
|
|
|
* Enable project custom taxonomies on LSX Banners. |
32
|
|
|
*/ |
33
|
|
|
public function lsx_banner_allowed_taxonomies( $taxonomies ) { |
34
|
|
|
$taxonomies[] = 'project-group'; |
35
|
|
|
return $taxonomies; |
36
|
|
|
} |
|
|
|
|
37
|
|
|
|
38
|
|
|
/** |
|
|
|
|
39
|
|
|
* Returns the shortcode output markup |
40
|
|
|
*/ |
41
|
|
|
public function output( $atts ) { |
42
|
|
|
// @codingStandardsIgnoreLine |
43
|
|
|
extract( shortcode_atts( array( |
44
|
|
|
'columns' => 3, |
|
|
|
|
45
|
|
|
'orderby' => 'name', |
|
|
|
|
46
|
|
|
'order' => 'ASC', |
|
|
|
|
47
|
|
|
'limit' => '-1', |
|
|
|
|
48
|
|
|
'include' => '', |
|
|
|
|
49
|
|
|
'display' => 'excerpt', |
|
|
|
|
50
|
|
|
'size' => 'lsx-thumbnail-single', |
|
|
|
|
51
|
|
|
'responsive' => 'true', |
52
|
|
|
'show_image' => 'true', |
53
|
|
|
'carousel' => 'true', |
|
|
|
|
54
|
|
|
'featured' => 'false', |
|
|
|
|
55
|
|
|
), $atts ) ); |
|
|
|
|
56
|
|
|
|
57
|
|
|
$output = ''; |
58
|
|
|
|
59
|
|
|
if ( 'true' === $responsive || true === $responsive ) { |
|
|
|
|
60
|
|
|
$responsive = ' img-responsive'; |
61
|
|
|
} else { |
62
|
|
|
$responsive = ''; |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
$this->columns = $columns; |
|
|
|
|
66
|
|
|
$this->responsive = $responsive; |
67
|
|
|
|
68
|
|
|
if ( ! empty( $include ) ) { |
|
|
|
|
69
|
|
|
$include = explode( ',', $include ); |
70
|
|
|
|
71
|
|
|
$args = array( |
72
|
|
|
'post_type' => 'project', |
|
|
|
|
73
|
|
|
'posts_per_page' => $limit, |
74
|
|
|
'post__in' => $include, |
|
|
|
|
75
|
|
|
'orderby' => 'post__in', |
|
|
|
|
76
|
|
|
'order' => $order, |
|
|
|
|
77
|
|
|
); |
78
|
|
|
} else { |
79
|
|
|
$args = array( |
80
|
|
|
'post_type' => 'project', |
|
|
|
|
81
|
|
|
'posts_per_page' => $limit, |
82
|
|
|
'orderby' => $orderby, |
|
|
|
|
83
|
|
|
'order' => $order, |
|
|
|
|
84
|
|
|
); |
85
|
|
|
|
86
|
|
|
if ( 'true' === $featured || true === $featured ) { |
|
|
|
|
87
|
|
|
$args['meta_key'] = 'lsx_project_featured'; |
|
|
|
|
88
|
|
|
$args['meta_value'] = 1; |
|
|
|
|
89
|
|
|
} |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
$projects = new \WP_Query( $args ); |
93
|
|
|
|
94
|
|
|
if ( $projects->have_posts() ) { |
|
|
|
|
95
|
|
|
global $post; |
96
|
|
|
|
97
|
|
|
$count = 0; |
|
|
|
|
98
|
|
|
$count_global = 0; |
99
|
|
|
|
100
|
|
|
if ( 'true' === $carousel || true === $carousel ) { |
|
|
|
|
101
|
|
|
$output .= "<div id='lsx-projects-slider' class='lsx-projects-shortcode' data-slick='{\"slidesToShow\": $columns, \"slidesToScroll\": $columns }'>"; |
102
|
|
|
} else { |
103
|
|
|
$output .= "<div class='lsx-projects-shortcode'><div class='row'>"; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
while ( $projects->have_posts() ) { |
|
|
|
|
107
|
|
|
$projects->the_post(); |
108
|
|
|
|
109
|
|
|
// Count |
|
|
|
|
110
|
|
|
$count++; |
111
|
|
|
$count_global++; |
112
|
|
|
|
113
|
|
|
// Content |
|
|
|
|
114
|
|
|
if ( 'full' === $display ) { |
|
|
|
|
115
|
|
|
$content = apply_filters( 'the_content', get_the_content() ); |
116
|
|
|
$content = str_replace( ']]>', ']]>', $content ); |
117
|
|
|
} elseif ( 'excerpt' === $display ) { |
|
|
|
|
118
|
|
|
$content = apply_filters( 'the_excerpt', get_the_excerpt() ); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
// Image |
|
|
|
|
122
|
|
|
if ( 'true' === $show_image || true === $show_image ) { |
|
|
|
|
123
|
|
|
if ( is_numeric( $size ) ) { |
|
|
|
|
124
|
|
|
$thumb_size = array( $size, $size ); |
125
|
|
|
} else { |
126
|
|
|
$thumb_size = $size; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
if ( ! empty( get_the_post_thumbnail( $post->ID ) ) ) { |
|
|
|
|
130
|
|
|
$image = get_the_post_thumbnail( $post->ID, $thumb_size, array( |
|
|
|
|
131
|
|
|
'class' => $responsive, |
132
|
|
|
) ); |
|
|
|
|
133
|
|
|
} else { |
134
|
|
|
$image = ''; |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
if ( empty( $image ) ) { |
|
|
|
|
138
|
|
|
if ( ! empty( $this->options['display']['projects_placeholder'] ) ) { |
|
|
|
|
139
|
|
|
$image = '<img class="' . $responsive . '" src="' . $this->options['display']['projects_placeholder'] . '" width="' . $size . '" alt="placeholder" />'; |
140
|
|
|
} else { |
141
|
|
|
$image = ''; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} else { |
145
|
|
|
$image = ''; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
// Project groups |
|
|
|
|
149
|
|
|
$groups = ''; |
150
|
|
|
$terms = get_the_terms( $post->ID, 'project-group' ); |
|
|
|
|
151
|
|
|
|
152
|
|
|
if ( $terms && ! is_wp_error( $terms ) ) { |
|
|
|
|
153
|
|
|
$groups = array(); |
154
|
|
|
|
155
|
|
|
foreach ( $terms as $term ) { |
|
|
|
|
156
|
|
|
$groups[] = $term->name; |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
$groups = join( ', ', $groups ); |
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
$project_groups = '' !== $groups ? "<p class='lsx-projects-groups'>$groups</p>" : ''; |
163
|
|
|
|
164
|
|
|
if ( 'true' === $carousel || true === $carousel ) { |
|
|
|
|
165
|
|
|
$output .= " |
166
|
|
|
<div class='lsx-projects-slot'> |
167
|
|
|
" . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
|
|
|
|
168
|
|
|
<h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
169
|
|
|
$project_groups |
170
|
|
|
<div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
171
|
|
|
</div>'; |
172
|
|
|
} elseif ( $columns >= 1 && $columns <= 4 ) { |
|
|
|
|
173
|
|
|
$md_col_width = 12 / $columns; |
174
|
|
|
|
175
|
|
|
$output .= " |
176
|
|
|
<div class='col-xs-12 col-md-" . $md_col_width . "'> |
177
|
|
|
<div class='lsx-projects-slot'> |
178
|
|
|
" . ( ! empty( $image ) ? "<a href='" . get_permalink() . "'><figure class='lsx-projects-avatar'>$image</figure></a>" : '' ) . " |
179
|
|
|
<h5 class='lsx-projects-title'><a href='" . get_permalink() . "'>" . apply_filters( 'the_title', $post->post_title ) . "</a></h5> |
180
|
|
|
$project_groups |
181
|
|
|
<div class='lsx-projects-content'><a href='" . get_permalink() . "' class='moretag'>" . esc_html__( 'View more', 'lsx-projects' ) . '</a></div> |
182
|
|
|
</div> |
183
|
|
|
</div>'; |
184
|
|
|
|
185
|
|
|
if ( $count == $columns && $projects->post_count > $count_global ) { |
|
|
|
|
186
|
|
|
$output .= '</div>'; |
187
|
|
|
$output .= "<div class='row'>"; |
188
|
|
|
$count = 0; |
|
|
|
|
189
|
|
|
} |
190
|
|
|
} else { |
191
|
|
|
$output .= " |
192
|
|
|
<p class='bg-warning' style='padding: 20px;'> |
193
|
|
|
" . esc_html__( 'Invalid number of columns set. LSX Projects supports 1 to 4 columns.', 'lsx-projects' ) . ' |
194
|
|
|
</p>'; |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
wp_reset_postdata(); |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
if ( 'true' !== $carousel && true !== $carousel ) { |
|
|
|
|
201
|
|
|
$output .= '</div>'; |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
$output .= '</div>'; |
205
|
|
|
|
206
|
|
|
return $output; |
207
|
|
|
} |
208
|
|
|
} |
|
|
|
|
209
|
|
|
|
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
global $lsx_projects; |
213
|
|
|
$lsx_projects = new LSX_Projects(); |
214
|
|
|
|