[ 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   *
   5   * Description: A Page Template that showcases Sticky Posts, Asides, and Blog Posts.
   6   *
   7   * The showcase template in Twenty Eleven consists of a featured posts section using sticky posts,
   8   * another recent posts area (with the latest post shown in full and the rest as a list)
   9   * and a left sidebar holding aside posts.
  10   *
  11   * We are creating two queries to fetch the proper posts and a custom widget for the sidebar.
  12   *
  13   * @package WordPress
  14   * @subpackage Twenty_Eleven
  15   * @since Twenty Eleven 1.0
  16   */
  17  
  18  // Enqueue showcase script for the slider.
  19  wp_enqueue_script( 'twentyeleven-showcase', get_template_directory_uri() . '/js/showcase.js', array( 'jquery' ), '20110429' );
  20  
  21  get_header(); ?>
  22  
  23          <div id="primary" class="showcase">
  24              <div id="content" role="main">
  25  
  26                  <?php
  27                  while ( have_posts() ) :
  28                      the_post();
  29                      ?>
  30  
  31                      <?php
  32                      /*
  33                       * We are using a heading by rendering the_content
  34                       * If we have content for this page, let's display it.
  35                       */
  36                      if ( '' !== get_the_content() ) {
  37                          get_template_part( 'content', 'intro' );
  38                      }
  39                      ?>
  40  
  41                  <?php endwhile; ?>
  42  
  43                  <?php
  44                      /*
  45                       * Begin the featured posts section.
  46                       *
  47                       * See if we have any sticky posts and use them to create our featured posts.
  48                       * We limit the featured posts at ten.
  49                       */
  50                      $sticky = get_option( 'sticky_posts' );
  51  
  52                      // Proceed only if sticky posts exist.
  53                  if ( ! empty( $sticky ) ) :
  54  
  55                      $featured_args = array(
  56                          'post__in'       => $sticky,
  57                          'post_status'    => 'publish',
  58                          'posts_per_page' => 10,
  59                          'no_found_rows'  => true,
  60                      );
  61  
  62                      // The Featured Posts query.
  63                      $featured = new WP_Query( $featured_args );
  64  
  65                      // Proceed only if published posts exist.
  66                      if ( $featured->have_posts() ) :
  67  
  68                          /*
  69                          * We will need to count featured posts starting from zero
  70                          * to create the slider navigation.
  71                          */
  72                          $counter_slider = 0;
  73  
  74                          // Compatibility with versions of WordPress prior to 3.4.
  75                          if ( function_exists( 'get_custom_header' ) ) {
  76                              $header_image_width = get_theme_support( 'custom-header', 'width' );
  77                          } else {
  78                              $header_image_width = HEADER_IMAGE_WIDTH;
  79                          }
  80                          ?>
  81  
  82                      <div class="featured-posts">
  83                      <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
  84  
  85                          <?php
  86                          // Let's roll.
  87                          while ( $featured->have_posts() ) :
  88                              $featured->the_post();
  89  
  90                              // Increase the counter.
  91                              $counter_slider++;
  92  
  93                              /*
  94                              * We're going to add a class to our featured post for featured images.
  95                              * By default it will have the feature-text class.
  96                              */
  97                              $feature_class = 'feature-text';
  98  
  99                              if ( has_post_thumbnail() ) {
 100                                  // ...but if it has a featured image let's add some class.
 101                                  $feature_class = 'feature-image small';
 102  
 103                                  // Hang on. Let's check this here image out.
 104                                  $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) );
 105  
 106                                  // Is it bigger than or equal to our header?
 107                                  if ( $image[1] >= $header_image_width ) {
 108                                      // If bigger, let's add a BIGGER class. It's EXTRA classy now.
 109                                      $feature_class = 'feature-image large';
 110                                  }
 111                              }
 112                              ?>
 113  
 114                      <section class="featured-post <?php echo esc_attr( $feature_class ); ?>" id="featured-post-<?php echo esc_attr( $counter_slider ); ?>">
 115  
 116                              <?php
 117                                  /*
 118                                   * If the thumbnail is as big as the header image
 119                                   * make it a large featured post, otherwise render it small
 120                                   */
 121                              if ( has_post_thumbnail() ) {
 122                                  if ( $image[1] >= $header_image_width ) {
 123                                      $thumbnail_size = 'large-feature';
 124                                  } else {
 125                                      $thumbnail_size = 'small-feature';
 126                                  }
 127  
 128                                  /* translators: %s: Post title. */
 129                                  $title = sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) );
 130                                  ?>
 131                          <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( $title ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
 132                                  <?php
 133                              }
 134                              ?>
 135                              <?php get_template_part( 'content', 'featured' ); ?>
 136                      </section>
 137                          <?php endwhile; ?>
 138  
 139                          <?php
 140                          // Show slider only if we have more than one featured post.
 141                          if ( $featured->post_count > 1 ) :
 142                              ?>
 143                      <nav class="feature-slider">
 144                      <ul>
 145                              <?php
 146  
 147                              // Reset the counter so that we end up with matching elements.
 148                              $counter_slider = 0;
 149  
 150                              // Begin from zero.
 151                              rewind_posts();
 152  
 153                              // Let's roll again.
 154                              while ( $featured->have_posts() ) :
 155                                  $featured->the_post();
 156                                  $counter_slider++;
 157                                  if ( 1 == $counter_slider ) {
 158                                      $class = ' class="active"';
 159                                  } else {
 160                                      $class = '';
 161                                  }
 162  
 163                                  /* translators: %s: Post title. */
 164                                  $title = sprintf( __( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) );
 165                                  ?>
 166                      <li><a href="#featured-post-<?php echo esc_attr( $counter_slider ); ?>" title="<?php echo esc_attr( $title ); ?>"<?php echo $class; ?>></a></li>
 167                          <?php endwhile; ?>
 168                      </ul>
 169                      </nav>
 170                      <?php endif; // End check for more than one sticky post. ?>
 171                      </div><!-- .featured-posts -->
 172                      <?php endif; // End check for published posts. ?>
 173                  <?php endif; // End check for sticky posts. ?>
 174  
 175                  <section class="recent-posts">
 176                      <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1>
 177  
 178                      <?php
 179  
 180                      // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
 181                      $recent_args = array(
 182                          'order'         => 'DESC',
 183                          'post__not_in'  => get_option( 'sticky_posts' ),
 184                          'tax_query'     => array(
 185                              array(
 186                                  'taxonomy' => 'post_format',
 187                                  'terms'    => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
 188                                  'field'    => 'slug',
 189                                  'operator' => 'NOT IN',
 190                              ),
 191                          ),
 192                          'no_found_rows' => true,
 193                      );
 194  
 195                      // Our new query for the Recent Posts section.
 196                      $recent = new WP_Query( $recent_args );
 197  
 198                      // The first Recent post is displayed normally.
 199                      if ( $recent->have_posts() ) :
 200                          $recent->the_post();
 201  
 202                          // Set $more to 0 in order to only get the first part of the post.
 203                          global $more;
 204                          $more = 0;
 205  
 206                          get_template_part( 'content', get_post_format() );
 207  
 208                          echo '<ol class="other-recent-posts">';
 209  
 210                      endif;
 211  
 212                      // For all other recent posts, just display the title and comment status.
 213                      while ( $recent->have_posts() ) :
 214                          $recent->the_post();
 215                          ?>
 216  
 217                          <li class="entry-title">
 218                              <a href="<?php the_permalink(); ?>" rel="bookmark"><?php the_title(); ?></a>
 219                              <span class="comments-link">
 220                                  <?php comments_popup_link( '<span class="leave-reply">' . __( 'Leave a reply', 'twentyeleven' ) . '</span>', __( '<b>1</b> Reply', 'twentyeleven' ), __( '<b>%</b> Replies', 'twentyeleven' ) ); ?>
 221                              </span>
 222                          </li>
 223  
 224                          <?php
 225                      endwhile;
 226  
 227                      // If we had some posts, close the <ol>.
 228                      if ( $recent->post_count > 0 ) {
 229                          echo '</ol>';
 230                      }
 231                      ?>
 232                  </section><!-- .recent-posts -->
 233  
 234                  <div class="widget-area" role="complementary">
 235                      <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
 236  
 237                          <?php
 238                          the_widget(
 239                              'Twenty_Eleven_Ephemera_Widget',
 240                              '',
 241                              array(
 242                                  'before_title' => '<h3 class="widget-title">',
 243                                  'after_title'  => '</h3>',
 244                              )
 245                          );
 246                          ?>
 247  
 248                      <?php endif; // End sidebar widget area. ?>
 249                  </div><!-- .widget-area -->
 250  
 251              </div><!-- #content -->
 252          </div><!-- #primary -->
 253  
 254  <?php get_footer(); ?>


Generated: Sun Apr 28 01:00:03 2024 Cross-referenced by PHPXref 0.7.1