| [ XREF Home ] [ Index ] |
PHP Cross Reference of WordPress TrunkProvided by Yoast |
[Summary view] [Print] [Text view]
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 $featured_args = array( 45 'post__in' => $sticky, 46 'post_status' => 'publish', 47 'posts_per_page' => 10, 48 ); 49 50 // The Featured Posts query. 51 $featured = new WP_Query( $featured_args ); 52 53 // Proceed only if sticky posts exist. 54 if ( $featured->have_posts() ) : 55 56 /** 57 * We will need to count featured posts starting from zero 58 * to create the slider navigation. 59 */ 60 $counter_slider = 0; 61 62 ?> 63 64 <div class="featured-posts"> 65 <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1> 66 67 <?php 68 // Let's roll. 69 while ( $featured->have_posts() ) : $featured->the_post(); 70 71 // Increase the counter. 72 $counter_slider++; 73 74 /** 75 * We're going to add a class to our featured post for featured images 76 * by default it'll have no class though. 77 */ 78 $feature_class = ''; 79 80 if ( has_post_thumbnail() ) { 81 // ... but if it has a featured image let's add some class 82 $feature_class = 'feature-image small'; 83 84 // Hang on. Let's check this here image out. 85 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ); 86 87 // Is it bigger than or equal to our header? 88 if ( $image[1] >= HEADER_IMAGE_WIDTH ) { 89 // If bigger, let's add a BIGGER class. It's EXTRA classy now. 90 $feature_class = 'feature-image large'; 91 } 92 } 93 ?> 94 95 <?php if ( has_post_thumbnail() ) : ?> 96 <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>"> 97 <?php else : ?> 98 <section class="featured-post" id="featured-post-<?php echo $counter_slider; ?>"> 99 <?php endif; ?> 100 101 <?php 102 /** 103 * If the thumbnail is as big as the header image 104 * make it a large featured post, otherwise render it small 105 */ 106 if ( has_post_thumbnail() ) { 107 if ( $image[1] >= HEADER_IMAGE_WIDTH ) { ?> 108 <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( 'large-feature' ); ?></a> 109 <?php } else { ?> 110 <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( 'small-feature' ); ?></a> 111 <?php } 112 } 113 ?> 114 <?php get_template_part( 'content', 'featured' ); ?> 115 </section> 116 <?php endwhile; ?> 117 118 <?php 119 // Show slider only if we have more than one featured post. 120 if ( $featured->post_count > 1 ) : 121 ?> 122 <nav class="feature-slider"> 123 <ul> 124 <?php 125 /** 126 * We need to query the same set of posts again 127 * to populate the navigation dots 128 */ 129 $featured->query( $featured_args ); 130 131 // Reset the counter so that we end up with matching elements 132 $counter_slider = 0; 133 134 // Begin from zero 135 rewind_posts(); 136 137 // Let's roll again. 138 while ( $featured->have_posts() ) : $featured->the_post(); 139 $counter_slider++; 140 ?> 141 <li><a href="#featured-post-<?php echo $counter_slider; ?>" title="<?php printf( esc_attr__( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" <?php 142 if ( 1 == $counter_slider ) : 143 echo 'class="active"'; 144 endif; 145 ?>></a></li> 146 <?php endwhile; ?> 147 </ul> 148 </nav> 149 <?php endif; // End check for more than one sticky post. ?> 150 </div><!-- .featured-posts --> 151 <?php endif; // End check for sticky posts. ?> 152 153 <section class="recent-posts"> 154 <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1> 155 156 <?php 157 158 // Display our recent posts, showing full content for the very latest, ignoring Aside posts. 159 $recent_args = array( 160 'order' => 'DESC', 161 'post__not_in' => get_option( 'sticky_posts' ), 162 'tax_query' => array( 163 array( 164 'taxonomy' => 'post_format', 165 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ), 166 'field' => 'slug', 167 'operator' => 'NOT IN', 168 ), 169 ), 170 ); 171 // Our new query for the Recent Posts section. 172 $recent = new WP_Query(); 173 $recent->query( $recent_args ); 174 $counter = 0; 175 176 while ( $recent->have_posts() ) : $recent->the_post(); 177 // Set $more to 0 in order to only get the first part of the post. 178 global $more; 179 $more = 0; 180 $counter++; 181 182 if ( 1 == $counter ) : 183 get_template_part( 'content', get_post_format() ); 184 echo '<ol class="other-recent-posts">'; 185 186 else : ?> 187 <li class="entry-title"> 188 <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> 189 <span class="comments-link"> 190 <?php comments_popup_link( __( '<span class="leave-reply">Leave a reply</span>', 'twentyeleven' ), __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?> 191 </span> 192 </li> 193 194 <?php endif; 195 endwhile; 196 ?> 197 198 </ol> 199 </section><!-- .recent-posts --> 200 201 <div class="widget-area" role="complementary"> 202 <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?> 203 204 <?php 205 the_widget( 'Twenty_Eleven_Ephemera_Widget', '', 'before_title=<h1 class="widget-title">&after_title=</h1>' ); 206 ?> 207 208 <?php endif; // end sidebar widget area ?> 209 </div><!-- .widget-area --> 210 211 </div><!-- #content --> 212 </div><!-- #primary --> 213 214 <?php get_footer(); ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jun 1 08:30:02 2011 |
Cross-referenced by PHPXref 0.7 Provided by Yoast and awesome WordPress Hosting |