3 * Template Name: Showcase Template
4 * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts
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.
10 * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
13 * @subpackage Twenty_Eleven
14 * @since Twenty Eleven 1.0
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' );
22 <div id="primary" class="showcase">
23 <div id="content" role="main">
25 <?php while ( have_posts() ) : the_post(); ?>
29 * We are using a heading by rendering the_content
30 * If we have content for this page, let's display it.
32 if ( '' != get_the_content() )
33 get_template_part( 'content', 'intro' );
40 * Begin the featured posts section.
42 * See if we have any sticky posts and use them to create our featured posts.
43 * We limit the featured posts at ten.
45 $sticky = get_option( 'sticky_posts' );
47 // Proceed only if sticky posts exist.
48 if ( ! empty( $sticky ) ) :
50 $featured_args = array(
51 'post__in' => $sticky,
52 'post_status' => 'publish',
53 'posts_per_page' => 10,
54 'no_found_rows' => true,
57 // The Featured Posts query.
58 $featured = new WP_Query( $featured_args );
60 // Proceed only if published posts exist
61 if ( $featured->have_posts() ) :
64 * We will need to count featured posts starting from zero
65 * to create the slider navigation.
71 <div class="featured-posts">
72 <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
76 while ( $featured->have_posts() ) : $featured->the_post();
78 // Increase the counter.
82 * We're going to add a class to our featured post for featured images
83 * by default it'll have the feature-text class.
85 $feature_class = 'feature-text';
87 if ( has_post_thumbnail() ) {
88 // ... but if it has a featured image let's add some class
89 $feature_class = 'feature-image small';
91 // Hang on. Let's check this here image out.
92 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) );
94 // Is it bigger than or equal to our header?
95 if ( $image[1] >= HEADER_IMAGE_WIDTH ) {
96 // If bigger, let's add a BIGGER class. It's EXTRA classy now.
97 $feature_class = 'feature-image large';
102 <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>">
106 * If the thumbnail is as big as the header image
107 * make it a large featured post, otherwise render it small
109 if ( has_post_thumbnail() ) {
110 if ( $image[1] >= HEADER_IMAGE_WIDTH )
111 $thumbnail_size = 'large-feature';
113 $thumbnail_size = 'small-feature';
115 <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>
119 <?php get_template_part( 'content', 'featured' ); ?>
124 // Show slider only if we have more than one featured post.
125 if ( $featured->post_count > 1 ) :
127 <nav class="feature-slider">
131 // Reset the counter so that we end up with matching elements
138 while ( $featured->have_posts() ) : $featured->the_post();
140 if ( 1 == $counter_slider )
141 $class = 'class="active"';
145 <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>
149 <?php endif; // End check for more than one sticky post. ?>
150 </div><!-- .featured-posts -->
151 <?php endif; // End check for published posts. ?>
152 <?php endif; // End check for sticky posts. ?>
154 <section class="recent-posts">
155 <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
159 // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
160 $recent_args = array(
162 'post__not_in' => get_option( 'sticky_posts' ),
163 'tax_query' => array(
165 'taxonomy' => 'post_format',
166 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
168 'operator' => 'NOT IN',
171 'no_found_rows' => true,
174 // Our new query for the Recent Posts section.
175 $recent = new WP_Query( $recent_args );
177 // The first Recent post is displayed normally
178 if ( $recent->have_posts() ) : $recent->the_post();
180 // Set $more to 0 in order to only get the first part of the post.
184 get_template_part( 'content', get_post_format() );
186 echo '<ol class="other-recent-posts">';
190 // For all other recent posts, just display the title and comment status.
191 while ( $recent->have_posts() ) : $recent->the_post(); ?>
193 <li class="entry-title">
194 <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>
195 <span class="comments-link">
196 <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentyeleven' ) . '</span>', __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?>
203 // If we had some posts, close the <ol>
204 if ( $recent->post_count > 0 )
207 </section><!-- .recent-posts -->
209 <div class="widget-area" role="complementary">
210 <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
213 the_widget( 'Twenty_Eleven_Ephemera_Widget', '', array( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
216 <?php endif; // end sidebar widget area ?>
217 </div><!-- .widget-area -->
219 </div><!-- #content -->
220 </div><!-- #primary -->
222 <?php get_footer(); ?>