[ Index ]

PHP Cross Reference of WordPress Trunk (Updated Daily)

Search

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


Generated : Sat Dec 21 08:20:01 2024 Cross-referenced by PHPXref