PageRenderTime 48ms CodeModel.GetById 19ms RepoModel.GetById 1ms app.codeStats 0ms

/wp-content/themes/twentyeleven/showcase.php

https://github.com/coffeant/wordpress
PHP | 205 lines | 116 code | 35 blank | 54 comment | 18 complexity | 1771b9af5330caab82d9ab2a1ee93838 MD5 | raw file
Possible License(s): AGPL-1.0, LGPL-2.1
  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. // Enqueue showcase script for the slider
  17. wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '2011-04-28' );
  18. get_header(); ?>
  19. <div id="primary" class="showcase">
  20. <div id="content" role="main">
  21. <?php the_post(); ?>
  22. <?php
  23. /**
  24. * We are using a heading by rendering the_content
  25. * If we have content for this page, let's display it.
  26. */
  27. if ( '' != get_the_content() )
  28. get_template_part( 'content', 'intro' );
  29. ?>
  30. <?php
  31. /**
  32. * Begin the featured posts section.
  33. *
  34. * See if we have any sticky posts and use them to create our featured posts.
  35. * We limit the featured posts at ten.
  36. */
  37. $sticky = get_option( 'sticky_posts' );
  38. $featured_args = array(
  39. 'posts_per_page' => 10,
  40. 'post__in' => $sticky,
  41. );
  42. // The Featured Posts query.
  43. $featured = new WP_Query();
  44. $featured->query( $featured_args );
  45. /**
  46. * We will need to count featured posts starting from zero
  47. * to create the slider navigation.
  48. */
  49. $counter_slider = 0;
  50. ?>
  51. <div class="featured-posts">
  52. <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
  53. <?php
  54. // Let's roll.
  55. while ( $featured->have_posts() ) : $featured->the_post();
  56. // Increase the counter.
  57. $counter_slider++;
  58. /**
  59. * We're going to add a class to our featured post for featured images
  60. * by default it'll have no class though.
  61. */
  62. $feature_class = '';
  63. if ( has_post_thumbnail() ) {
  64. // ... but if it has a featured image let's add some class
  65. $feature_class = 'feature-image small';
  66. // Hang on. Let's check this here image out.
  67. $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) );
  68. // Is it bigger than or equal to our header?
  69. if ( $image[1] >= HEADER_IMAGE_WIDTH ) {
  70. // If bigger, let's add a BIGGER class. It's EXTRA classy now.
  71. $feature_class = 'feature-image large';
  72. }
  73. }
  74. ?>
  75. <?php if ( has_post_thumbnail() ) : ?>
  76. <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>">
  77. <?php else : ?>
  78. <section class="featured-post" id="featured-post-<?php echo $counter_slider; ?>">
  79. <?php endif; ?>
  80. <?php
  81. /**
  82. * If the thumbnail is as big as the header image
  83. * make it a large featured post, otherwise render it small
  84. */
  85. if ( has_post_thumbnail() ) {
  86. if ( $image[1] >= HEADER_IMAGE_WIDTH ) { ?>
  87. <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>
  88. <?php } else { ?>
  89. <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>
  90. <?php }
  91. }
  92. ?>
  93. <?php get_template_part( 'content', 'featured' ); ?>
  94. </section>
  95. <?php endwhile; ?>
  96. <nav class="feature-slider">
  97. <ul>
  98. <?php
  99. /**
  100. * We need to query the same set of posts again
  101. * to populate the navigation dots
  102. */
  103. $featured->query( $featured_args );
  104. // Reset the counter so that we end up with matching elements
  105. $counter_slider = 0;
  106. // Begin from zero
  107. rewind_posts();
  108. // Let's roll again.
  109. while ( $featured->have_posts() ) : $featured->the_post();
  110. $counter_slider++;
  111. ?>
  112. <li><a href="#featured-post-<?php echo $counter_slider; ?>" title="<?php printf( esc_attr__( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ); ?>" <?php
  113. if ( 1 == $counter_slider ) :
  114. echo 'class="active"';
  115. endif;
  116. ?>></a></li>
  117. <?php endwhile; ?>
  118. </ul>
  119. </nav>
  120. </div>
  121. <section class="recent-posts">
  122. <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
  123. <?php
  124. // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
  125. $recent_args = array(
  126. 'order' => 'DESC',
  127. 'post__not_in' => get_option( 'sticky_posts' ),
  128. 'tax_query' => array(
  129. array(
  130. 'taxonomy' => 'post_format',
  131. 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
  132. 'field' => 'slug',
  133. 'operator' => 'NOT IN',
  134. ),
  135. ),
  136. );
  137. // Our new query for the Recent Posts section.
  138. $recent = new WP_Query();
  139. $recent->query( $recent_args );
  140. $counter = 0;
  141. while ( $recent->have_posts() ) : $recent->the_post();
  142. // Set $more to 0 in order to only get the first part of the post.
  143. global $more;
  144. $more = 0;
  145. $counter++;
  146. if ( 1 == $counter ) :
  147. get_template_part( 'content', get_post_format() );
  148. echo '<ol class="other-recent-posts">';
  149. else : ?>
  150. <li class="entry-title">
  151. <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>
  152. <span class="comments-link">
  153. <?php comments_popup_link( __( '<span class="leave-reply">Leave a reply</span>', 'twentyeleven' ), __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?>
  154. </span>
  155. </li>
  156. <?php endif;
  157. endwhile;
  158. ?>
  159. </ol>
  160. </section>
  161. <div class="widget-area" role="complementary">
  162. <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  163. <?php
  164. the_widget( 'Twenty_Eleven_Ephemera_Widget', '', 'before_title=<h1 class="widget-title">&after_title=</h1>' );
  165. ?>
  166. <?php endif; // end sidebar widget area ?>
  167. </div><!-- .widget-area -->
  168. </div><!-- #content -->
  169. </div><!-- #primary -->
  170. <?php get_footer(); ?>