PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

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

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