1 |
<?php |
2 |
/** |
3 |
* Template Name: Showcase Template |
4 |
* Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts |
5 |
* |
6 |
* The showcase template in Twenty Eleven consists of a featured posts section using sticky posts, |
7 |
* another recent posts area (with the latest post shown in full and the rest as a list) |
8 |
* and a left sidebar holding aside posts. |
9 |
* |
10 |
* We are creating two queries to fetch the proper posts and a custom widget for the sidebar. |
11 |
* |
12 |
* @package WordPress |
13 |
* @subpackage Twenty_Eleven |
14 |
* @since Twenty Eleven 1.0 |
15 |
*/ |
16 |
|
17 |
// Enqueue showcase script for the slider |
18 |
wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '2011-04-28' ); |
19 |
|
20 |
get_header(); ?> |
21 |
|
22 |
<div id="primary" class="showcase"> |
23 |
<div id="content" role="main"> |
24 |
|
25 |
<?php the_post(); ?> |
26 |
|
27 |
<?php |
28 |
/** |
29 |
* We are using a heading by rendering the_content |
30 |
* If we have content for this page, let's display it. |
31 |
*/ |
32 |
if ( '' != get_the_content() ) |
33 |
get_template_part( 'content', 'intro' ); |
34 |
?> |
35 |
|
36 |
<?php |
37 |
/** |
38 |
* Begin the featured posts section. |
39 |
* |
40 |
* See if we have any sticky posts and use them to create our featured posts. |
41 |
* We limit the featured posts at ten. |
42 |
*/ |
43 |
$sticky = get_option( 'sticky_posts' ); |
44 |
|
45 |
// Proceed only if sticky posts exist. |
46 |
if ( ! empty( $sticky ) ) : |
47 |
|
48 |
$featured_args = array( |
49 |
'post__in' => $sticky, |
50 |
'post_status' => 'publish', |
51 |
'posts_per_page' => 10, |
52 |
'no_found_rows' => true, |
53 |
); |
54 |
|
55 |
// The Featured Posts query. |
56 |
$featured = new WP_Query( $featured_args ); |
57 |
|
58 |
// Proceed only if published posts exist |
59 |
if ( $featured->have_posts() ) : |
60 |
|
61 |
/** |
62 |
* We will need to count featured posts starting from zero |
63 |
* to create the slider navigation. |
64 |
*/ |
65 |
$counter_slider = 0; |
66 |
|
67 |
?> |
68 |
|
69 |
<div class="featured-posts"> |
70 |
<h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1> |
71 |
|
72 |
<?php |
73 |
// Let's roll. |
74 |
while ( $featured->have_posts() ) : $featured->the_post(); |
75 |
|
76 |
// Increase the counter. |
77 |
$counter_slider++; |
78 |
|
79 |
/** |
80 |
* We're going to add a class to our featured post for featured images |
81 |
* by default it'll have the feature-text class. |
82 |
*/ |
83 |
$feature_class = 'feature-text'; |
84 |
|
85 |
if ( has_post_thumbnail() ) { |
86 |
// ... but if it has a featured image let's add some class |
87 |
$feature_class = 'feature-image small'; |
88 |
|
89 |
// Hang on. Let's check this here image out. |
90 |
$image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ); |
91 |
|
92 |
// Is it bigger than or equal to our header? |
93 |
if ( $image[1] >= HEADER_IMAGE_WIDTH ) { |
94 |
// If bigger, let's add a BIGGER class. It's EXTRA classy now. |
95 |
$feature_class = 'feature-image large'; |
96 |
} |
97 |
} |
98 |
?> |
99 |
|
100 |
<section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>"> |
101 |
|
102 |
<?php |
103 |
/** |
104 |
* If the thumbnail is as big as the header image |
105 |
* make it a large featured post, otherwise render it small |
106 |
*/ |
107 |
if ( has_post_thumbnail() ) { |
108 |
if ( $image[1] >= HEADER_IMAGE_WIDTH ) |
109 |
$thumbnail_size = 'large-feature'; |
110 |
else |
111 |
$thumbnail_size = 'small-feature'; |
112 |
?> |
113 |
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a> |
114 |
<?php |
115 |
} |
116 |
?> |
117 |
<?php get_template_part( 'content', 'featured' ); ?> |
118 |
</section> |
119 |
<?php endwhile; ?> |
120 |
|
121 |
<?php |
122 |
// Show slider only if we have more than one featured post. |
123 |
if ( $featured->post_count > 1 ) : |
124 |
?> |
125 |
<nav class="feature-slider"> |
126 |
<ul> |
127 |
<?php |
128 |
|
129 |
// Reset the counter so that we end up with matching elements |
130 |
$counter_slider = 0; |
131 |
|
132 |
// Begin from zero |
133 |
rewind_posts(); |
134 |
|
135 |
// Let's roll again. |
136 |
while ( $featured->have_posts() ) : $featured->the_post(); |
137 |
$counter_slider++; |
138 |
if ( 1 == $counter_slider ) |
139 |
$class = 'class="active"'; |
140 |
else |
141 |
$class = ''; |
142 |
?> |
143 |
<li><a href="#featured-post-<?php echo $counter_slider; ?>" title="<?php printf( esc_attr__( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" <?php echo $class; ?>></a></li> |
144 |
<?php endwhile; ?> |
145 |
</ul> |
146 |
</nav> |
147 |
<?php endif; // End check for more than one sticky post. ?> |
148 |
</div><!-- .featured-posts --> |
149 |
<?php endif; // End check for published posts. ?> |
150 |
<?php endif; // End check for sticky posts. ?> |
151 |
|
152 |
<section class="recent-posts"> |
153 |
<h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1> |
154 |
|
155 |
<?php |
156 |
|
157 |
// Display our recent posts, showing full content for the very latest, ignoring Aside posts. |
158 |
$recent_args = array( |
159 |
'order' => 'DESC', |
160 |
'post__not_in' => get_option( 'sticky_posts' ), |
161 |
'tax_query' => array( |
162 |
array( |
163 |
'taxonomy' => 'post_format', |
164 |
'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ), |
165 |
'field' => 'slug', |
166 |
'operator' => 'NOT IN', |
167 |
), |
168 |
), |
169 |
'no_found_rows' => true, |
170 |
); |
171 |
|
172 |
// Our new query for the Recent Posts section. |
173 |
$recent = new WP_Query( $recent_args ); |
174 |
|
175 |
// The first Recent post is displayed normally |
176 |
if ( $recent->have_posts() ) : $recent->the_post(); |
177 |
|
178 |
// Set $more to 0 in order to only get the first part of the post. |
179 |
global $more; |
180 |
$more = 0; |
181 |
|
182 |
get_template_part( 'content', get_post_format() ); |
183 |
|
184 |
echo '<ol class="other-recent-posts">'; |
185 |
|
186 |
endif; |
187 |
|
188 |
// For all other recent posts, just display the title and comment status. |
189 |
while ( $recent->have_posts() ) : $recent->the_post(); ?> |
190 |
|
191 |
<li class="entry-title"> |
192 |
<a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a> |
193 |
<span class="comments-link"> |
194 |
<?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentyeleven' ) . '</span>', __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?> |
195 |
</span> |
196 |
</li> |
197 |
|
198 |
<?php |
199 |
endwhile; |
200 |
|
201 |
// If we had some posts, close the <ol> |
202 |
if ( $recent->post_count > 0 ) |
203 |
echo '</ol>'; |
204 |
?> |
205 |
</section><!-- .recent-posts --> |
206 |
|
207 |
<div class="widget-area" role="complementary"> |
208 |
<?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?> |
209 |
|
210 |
<?php |
211 |
the_widget( 'Twenty_Eleven_Ephemera_Widget', '', array( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) ); |
212 |
?> |
213 |
|
214 |
<?php endif; // end sidebar widget area ?> |
215 |
</div><!-- .widget-area --> |
216 |
|
217 |
</div><!-- #content --> |
218 |
</div><!-- #primary --> |
219 |
|
220 |
<?php get_footer(); ?> |