PageRenderTime 27ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

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

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