[wp-trac] [WordPress Trac] #39771: Suggestion for edit to content-front-page.php in TwentySeventeen Theme

WordPress Trac noreply at wordpress.org
Thu Feb 2 20:42:21 UTC 2017


#39771: Suggestion for edit to content-front-page.php in TwentySeventeen Theme
-------------------------+-----------------------------
 Reporter:  dayun123     |      Owner:
     Type:  enhancement  |     Status:  new
 Priority:  normal       |  Milestone:  Awaiting Review
Component:  Themes       |    Version:  4.7.2
 Severity:  normal       |   Keywords:
  Focuses:               |
-------------------------+-----------------------------
 {{{#!php
 <?php if ( has_post_thumbnail() ) :
         $thumbnail = wp_get_attachment_image_src( get_post_thumbnail_id(
 $post->ID ), 'twentyseventeen-featured-image' );

         $post_thumbnail_id = get_post_thumbnail_id( $post->ID );

         $thumbnail_attributes = wp_get_attachment_image_src(
 get_post_thumbnail_id( $post->ID ), 'twentyseventeen-featured-image' );

         // Calculate aspect ratio: h / w * 100%.
         $ratio = $thumbnail_attributes[2] / $thumbnail_attributes[1] *
 100;
         ?>

         <div class="panel-image" style="background-image: url(<?php echo
 esc_url( $thumbnail[0] ); ?>);">
             <div class="panel-image-prop" style="padding-top: <?php echo
 esc_attr( $ratio ); ?>%"></div>
         </div><!-- .panel-image -->

 <?php endif; ?>
 }}}

 I'm still a novice programmer, so maybe I'm missing something obvious, but
 I don't understand why the following two things happen:

 1. Why is the $post_thumbnail_id variable created but never used? Why not
 create it right away instead of constantly calling get_post_thumbnail_id(
 $post->ID )?
 2. $thumbnail and $thumbnail_attributes are the same, right? So why create
 both?

 Wouldn't this make more sense:


 {{{#!php
 <?php if ( has_post_thumbnail() ) :

         $post_thumbnail_id = get_post_thumbnail_id( $post->ID );

         $thumbnail = wp_get_attachment_image_src( $post_thumbnail_id,
 'twentyseventeen-featured-image' );

         // Calculate aspect ratio: h / w * 100%.
         $ratio = $thumbnail[2] / $thumbnail[1] * 100;
         ?>

         <div class="panel-image" style="background-image: url(<?php echo
 esc_url( $thumbnail[0] ); ?>);">
             <div class="panel-image-prop" style="padding-top: <?php echo
 esc_attr( $ratio ); ?>%"></div>
         </div><!-- .panel-image -->

 <?php endif; ?>
 }}}

--
Ticket URL: <https://core.trac.wordpress.org/ticket/39771>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list