Make WordPress Core


Ignore:
Timestamp:
11/30/2017 11:09:33 PM (6 years ago)
Author:
pento
Message:

Code is Poetry.
WordPress' code just... wasn't.
This is now dealt with.

Props jrf, pento, netweb, GaryJ, jdgrimes, westonruter, Greg Sherwood from PHPCS, and everyone who's ever contributed to WPCS and PHPCS.
Fixes #41057.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-content/themes/twentyeleven/showcase.php

    r31265 r42343  
    2424            <div id="content" role="main">
    2525
    26                 <?php while ( have_posts() ) : the_post(); ?>
     26                <?php
     27                while ( have_posts() ) :
     28                    the_post();
     29                    ?>
    2730
    2831                <?php
     
    3134                     * If we have content for this page, let's display it.
    3235                     */
    33                     if ( '' != get_the_content() )
    34                         get_template_part( 'content', 'intro' );
     36                if ( '' != get_the_content() ) {
     37                    get_template_part( 'content', 'intro' );
     38                }
    3539                ?>
    3640
     
    4751
    4852                    // Proceed only if sticky posts exist.
    49                     if ( ! empty( $sticky ) ) :
     53                if ( ! empty( $sticky ) ) :
    5054
    5155                    $featured_args = array(
    52                         'post__in' => $sticky,
    53                         'post_status' => 'publish',
     56                        'post__in'       => $sticky,
     57                        'post_status'    => 'publish',
    5458                        'posts_per_page' => 10,
    55                         'no_found_rows' => true,
     59                        'no_found_rows'  => true,
    5660                    );
    5761
     
    6266                    if ( $featured->have_posts() ) :
    6367
    64                     /*
    65                      * We will need to count featured posts starting from zero
    66                      * to create the slider navigation.
    67                      */
    68                     $counter_slider = 0;
    69 
    70                     // Compatibility with versions of WordPress prior to 3.4.
    71                     if ( function_exists( 'get_custom_header' ) )
    72                         $header_image_width = get_theme_support( 'custom-header', 'width' );
    73                     else
    74                         $header_image_width = HEADER_IMAGE_WIDTH;
    75                 ?>
    76 
    77                 <div class="featured-posts">
     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">
    7883                    <h1 class="showcase-heading"><?php _e( 'Featured Post', 'twentyeleven' ); ?></h1>
    7984
    8085                <?php
    81                     // Let's roll.
    82                     while ( $featured->have_posts() ) : $featured->the_post();
     86                // Let's roll.
     87                while ( $featured->have_posts() ) :
     88                    $featured->the_post();
    8389
    8490                    // Increase the counter.
     
    8692
    8793                    /*
    88                      * We're going to add a class to our featured post for featured images
    89                      * by default it'll have the feature-text class.
    90                      */
     94                    * We're going to add a class to our featured post for featured images
     95                    * by default it'll have the feature-text class.
     96                    */
    9197                    $feature_class = 'feature-text';
    9298
     
    108114                    <section class="featured-post <?php echo esc_attr( $feature_class ); ?>" id="featured-post-<?php echo esc_attr( $counter_slider ); ?>">
    109115
    110                         <?php
    111                             /*
    112                              * If the thumbnail is as big as the header image
    113                              * make it a large featured post, otherwise render it small
    114                              */
    115                             if ( has_post_thumbnail() ) {
    116                                 if ( $image[1] >= $header_image_width )
    117                                     $thumbnail_size = 'large-feature';
    118                                 else
    119                                     $thumbnail_size = 'small-feature';
    120                                 ?>
    121                                 <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
    122                                 <?php
    123                             }
     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                        <a href="<?php the_permalink(); ?>" title="<?php echo esc_attr( sprintf( __( 'Permalink to %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>" rel="bookmark"><?php the_post_thumbnail( $thumbnail_size ); ?></a>
     129                            <?php
     130                    }
    124131                        ?>
    125132                        <?php get_template_part( 'content', 'featured' ); ?>
    126133                    </section>
    127                 <?php endwhile; ?>
    128 
    129                 <?php
     134                <?php endwhile; ?>
     135
     136                    <?php
    130137                    // Show slider only if we have more than one featured post.
    131138                    if ( $featured->post_count > 1 ) :
    132                 ?>
    133                 <nav class="feature-slider">
     139                    ?>
     140                    <nav class="feature-slider">
    134141                    <ul>
    135142                    <?php
    136143
    137                         // Reset the counter so that we end up with matching elements
    138                         $counter_slider = 0;
    139 
    140                         // Begin from zero
    141                         rewind_posts();
    142 
    143                         // Let's roll again.
    144                         while ( $featured->have_posts() ) : $featured->the_post();
    145                             $counter_slider++;
    146                             if ( 1 == $counter_slider )
    147                                 $class = ' class="active"';
    148                             else
    149                                 $class = '';
    150                         ?>
    151                         <li><a href="#featured-post-<?php echo esc_attr( $counter_slider ); ?>" title="<?php echo esc_attr( sprintf( __( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>"<?php echo $class; ?>></a></li>
    152                     <?php endwhile; ?>
     144                    // Reset the counter so that we end up with matching elements
     145                    $counter_slider = 0;
     146
     147                    // Begin from zero
     148                    rewind_posts();
     149
     150                    // Let's roll again.
     151                    while ( $featured->have_posts() ) :
     152                        $featured->the_post();
     153                        $counter_slider++;
     154                        if ( 1 == $counter_slider ) {
     155                            $class = ' class="active"';
     156                        } else {
     157                            $class = '';
     158                        }
     159                    ?>
     160                    <li><a href="#featured-post-<?php echo esc_attr( $counter_slider ); ?>" title="<?php echo esc_attr( sprintf( __( 'Featuring: %s', 'twentyeleven' ), the_title_attribute( 'echo=0' ) ) ); ?>"<?php echo $class; ?>></a></li>
     161                    <?php endwhile; ?>
    153162                    </ul>
    154                 </nav>
    155                 <?php endif; // End check for more than one sticky post. ?>
    156                 </div><!-- .featured-posts -->
    157                 <?php endif; // End check for published posts. ?>
     163                    </nav>
     164                    <?php endif; // End check for more than one sticky post. ?>
     165                    </div><!-- .featured-posts -->
     166                    <?php endif; // End check for published posts. ?>
    158167                <?php endif; // End check for sticky posts. ?>
    159168
     
    165174                    // Display our recent posts, showing full content for the very latest, ignoring Aside posts.
    166175                    $recent_args = array(
    167                         'order' => 'DESC',
    168                         'post__not_in' => get_option( 'sticky_posts' ),
    169                         'tax_query' => array(
     176                        'order'         => 'DESC',
     177                        'post__not_in'  => get_option( 'sticky_posts' ),
     178                        'tax_query'     => array(
    170179                            array(
    171180                                'taxonomy' => 'post_format',
    172                                 'terms' => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
    173                                 'field' => 'slug',
     181                                'terms'    => array( 'post-format-aside', 'post-format-link', 'post-format-quote', 'post-format-status' ),
     182                                'field'    => 'slug',
    174183                                'operator' => 'NOT IN',
    175184                            ),
     
    182191
    183192                    // The first Recent post is displayed normally
    184                     if ( $recent->have_posts() ) : $recent->the_post();
     193                    if ( $recent->have_posts() ) :
     194                        $recent->the_post();
    185195
    186196                        // Set $more to 0 in order to only get the first part of the post.
     
    195205
    196206                    // For all other recent posts, just display the title and comment status.
    197                     while ( $recent->have_posts() ) : $recent->the_post(); ?>
     207                    while ( $recent->have_posts() ) :
     208                        $recent->the_post();
     209                    ?>
    198210
    199211                        <li class="entry-title">
     
    208220
    209221                    // If we had some posts, close the <ol>
    210                     if ( $recent->post_count > 0 )
     222                    if ( $recent->post_count > 0 ) {
    211223                        echo '</ol>';
     224                    }
    212225                    ?>
    213226                </section><!-- .recent-posts -->
     
    217230
    218231                        <?php
    219                         the_widget( 'Twenty_Eleven_Ephemera_Widget', '', array( 'before_title' => '<h3 class="widget-title">', 'after_title' => '</h3>' ) );
     232                        the_widget(
     233                            'Twenty_Eleven_Ephemera_Widget', '', array(
     234                                'before_title' => '<h3 class="widget-title">',
     235                                'after_title'  => '</h3>',
     236                            )
     237                        );
    220238                        ?>
    221239
Note: See TracChangeset for help on using the changeset viewer.