WordPress.org

Make WordPress Core

Ticket #17198: 17198.showcase.2.diff

File 17198.showcase.2.diff, 3.5 KB (added by kawauso, 2 years ago)

showcase.php cleanup, 2nd pass

  • wp-content/themes/twentyeleven/showcase.php

     
    2323                                <?php 
    2424                                        // See if we have any sticky posts and use the latest to create a featured post 
    2525                                        $sticky = get_option( 'sticky_posts' ); 
    26                                         $featured_args = array( 
    27                                                 'posts_per_page' => 1, 
    28                                                 'post__in' => $sticky, 
    29                                         ); 
    30                                          
    31                                         $featured = new WP_Query(); 
    32                                         $featured->query( $featured_args ); 
    33                                  
     26 
    3427                                        // Let's roll. 
    3528                                        if ( $sticky ) : 
    36                                          
    37                                         $featured->the_post(); 
    38                                          
    39                                         // We're going to add a class to our featured post for featured images 
    40                                         // by default it'll have no class though 
    41                                         $feature_class = ''; 
    4229 
    43                                         if ( has_post_thumbnail() ) { 
    44                                                 // … but if it has a featured image let's add some class 
    45                                                 $feature_class = 'feature-image small'; 
     30                                                $featured_args = array( 
     31                                                        'posts_per_page' => 1, 
     32                                                        'post__in' => $sticky, 
     33                                                        'ignore_sticky_posts' => true, 
     34                                                ); 
    4635 
    47                                                 // Hang on. Let's check this here image out. 
    48                                                 $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ); 
     36                                                $featured = new WP_Query(); 
     37                                                $featured->query( $featured_args ); 
    4938 
    50                                                 // Is it bigger than or equal to our header? 
    51                                                 if ( $image[1] >= HEADER_IMAGE_WIDTH ) { 
    52                                                         // Let's add a BIGGER class. It's EXTRA classy now. 
    53                                                         $feature_class = 'feature-image large'; 
    54                                                 } 
    55                                         } 
    56                                         ?> 
    57                                  
    58                                 <?php if ( has_post_thumbnail() ) : ?> 
    59                                 <section class="featured-post <?php echo $feature_class; ?>"> 
    60                                 <?php else : ?> 
    61                                 <section class="featured-post"> 
    62                                 <?php endif; ?> 
     39                                                while ( $featured->have_posts() ) : $featured->the_post(); 
     40 
     41                                                        $feature_class = 'featured-post'; 
     42 
     43                                                        // We're going to add a class to our featured post for featured images 
     44                                                        if ( has_post_thumbnail() ) { 
     45                                                                // Hang on. Let's check this here image out. 
     46                                                                $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), array( HEADER_IMAGE_WIDTH, HEADER_IMAGE_WIDTH ) ); 
     47 
     48                                                                // Is it bigger than or equal to our header? 
     49                                                                if ( $image[1] >= HEADER_IMAGE_WIDTH ) { 
     50                                                                        // Let's add a BIGGER class. It's EXTRA classy now. 
     51                                                                        $feature_class .= ' feature-image large'; 
     52                                                                } else { 
     53                                                                        $feature_class .= ' feature-image small'; 
     54                                                                } 
     55                                                        } 
     56                                ?> 
     57 
     58                                <section class="<?php echo $feature_class; ?>"> 
    6359                                        <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1> 
    6460                                        <?php 
    6561                                                // Dynamic thumbnails! 
     
    7369                                        ?>                                       
    7470                                        <?php get_template_part( 'content', 'featured' ); ?> 
    7571                                </section>                                                       
    76                                 <?php endif; ?> 
     72                                        <?php endwhile; 
     73                                endif; 
     74                                ?> 
    7775 
    7876                                <section class="recent-posts"> 
    7977                                        <h1 class="showcase-heading"><?php _e( 'Recent Posts', 'twentyeleven' ); ?></h1> 
     
    9593                                        ); 
    9694                                        $recent = new WP_Query(); 
    9795                                        $recent->query( $recent_args ); 
    98                                         $counter = 0; 
    9996                                         
    10097                                        while ( $recent->have_posts() ) : $recent->the_post(); 
    10198                                                // set $more to 0 in order to only get the first part of the post 
    10299                                                global $more; 
    103100                                                $more = 0;                                       
    104                                                 $counter++; 
    105101                                                 
    106                                                 if ( 1 == $counter ) : 
     102                                                if ( 0 == $recent->current_post ) : 
    107103                                                        get_template_part( 'content', get_post_format() ); 
    108104                                                        echo '<ol class="other-recent-posts">'; 
    109105