[ Index ]

PHP Cross Reference of WordPress

title

Body

[close]

/wp-content/themes/twentyeleven/ -> showcase.php (source)

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


Generated: Fri May 25 03:56:23 2012 Hosted by follow the white rabbit.