Advertisement
alchymyth

showcase.php 2011 / recent posts removed

Oct 12th, 2012
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.59 KB | None | 0 0
  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.                     // Compatibility with versions of WordPress prior to 3.4.
  70.                     if ( function_exists( 'get_custom_header' ) )
  71.                         $header_image_width = get_theme_support( 'custom-header', 'width' );
  72.                     else
  73.                         $header_image_width = HEADER_IMAGE_WIDTH;
  74.                 ?>
  75.  
  76.                 <div class="featured-posts">
  77.                     <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
  78.  
  79.                 <?php
  80.                     // Let's roll.
  81.                     while ( $featured->have_posts() ) : $featured->the_post();
  82.  
  83.                     // Increase the counter.
  84.                     $counter_slider++;
  85.  
  86.                     /**
  87.                      * We're going to add a class to our featured post for featured images
  88.                      * by default it'll have the feature-text class.
  89.                      */
  90.                     $feature_class = 'feature-text';
  91.  
  92.                     if ( has_post_thumbnail() ) {
  93.                         // ... but if it has a featured image let's add some class
  94.                         $feature_class = 'feature-image small';
  95.  
  96.                         // Hang on. Let's check this here image out.
  97.                         $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( $header_image_width, $header_image_width ) );
  98.  
  99.                         // Is it bigger than or equal to our header?
  100.                         if ( $image[1] >= $header_image_width ) {
  101.                             // If bigger, let's add a BIGGER class. It's EXTRA classy now.
  102.                             $feature_class = 'feature-image large';
  103.                         }
  104.                     }
  105.                     ?>
  106.  
  107.                     <section class="featured-post <?php echo $feature_class; ?>" id="featured-post-<?php echo $counter_slider; ?>">
  108.  
  109.                         <?php
  110.                             /**
  111.                              * If the thumbnail is as big as the header image
  112.                              * make it a large featured post, otherwise render it small
  113.                              */
  114.                             if ( has_post_thumbnail() ) {
  115.                                 if ( $image[1] >= $header_image_width )
  116.                                     $thumbnail_size = 'large-feature';
  117.                                 else
  118.                                     $thumbnail_size = 'small-feature';
  119.                                 ?>
  120.                                 <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>
  121.                                 <?php
  122.                             }
  123.                         ?>
  124.                         <?php get_template_part( 'content', 'featured' ); ?>
  125.                     </section>
  126.                 <?php endwhile; ?>
  127.  
  128.                 <?php
  129.                     // Show slider only if we have more than one featured post.
  130.                     if ( $featured->post_count > 1 ) :
  131.                 ?>
  132.                 <nav class="feature-slider">
  133.                     <ul>
  134.                     <?php
  135.  
  136.                         // Reset the counter so that we end up with matching elements
  137.                         $counter_slider = 0;
  138.  
  139.                         // Begin from zero
  140.                         rewind_posts();
  141.  
  142.                         // Let's roll again.
  143.                         while ( $featured->have_posts() ) : $featured->the_post();
  144.                             $counter_slider++;
  145.                             if ( 1 == $counter_slider )
  146.                                 $class = 'class="active"';
  147.                             else
  148.                                 $class = '';
  149.                         ?>
  150.                         <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>
  151.                     <?php endwhile; ?>
  152.                     </ul>
  153.                 </nav>
  154.                 <?php endif; // End check for more than one sticky post. ?>
  155.                 </div><!-- .featured-posts -->
  156.                 <?php endif; // End check for published posts. ?>
  157.                 <?php endif; // End check for sticky posts. ?>
  158.  
  159.                 <!-- section recent posts was here and is deleted -->
  160.  
  161.                 <div class="widget-area" role="complementary">
  162.                     <?php if ( ! dynamic_sidebar( 'sidebar-2' ) ) : ?>
  163.  
  164.                         <?php
  165.                         the_widget( 'Twenty_Eleven_Ephemera_Widget', '', array( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
  166.                         ?>
  167.  
  168.                     <?php endif; // end sidebar widget area ?>
  169.                 </div><!-- .widget-area -->
  170.  
  171.             </div><!-- #content -->
  172.         </div><!-- #primary -->
  173.  
  174. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement