Twenty Seventeen: Display featured image on static front page

This improves UX, since an image added will be displayed on front end as opposed to not at all. This fix added the front page's featured image above the front page content, similar to how it's handled in the other panels. Also it removed code that was setting the front page's featured image as a fallback to the custom header, and updated the conditions that add the `has-header-image` to remove reference to the front page's featured image.

Props laurelfulford.

Fixes #38402.

Built from https://develop.svn.wordpress.org/trunk@38868


git-svn-id: http://core.svn.wordpress.org/trunk@38811 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
David A. Kennedy 2016-10-21 22:15:50 +00:00
parent 0794b2489b
commit e58856bbd0
4 changed files with 20 additions and 12 deletions

View File

@ -19,15 +19,6 @@
<div class="custom-header-image" style="background-image: url(<?php echo esc_url( $header_image ); ?>)"></div>
<?php get_template_part( 'components/header/site', 'branding' ); ?>
<?php elseif ( twentyseventeen_is_frontpage() && has_post_thumbnail() ) :
// If not, fall back to front page's featured image, only on the front page.
$post_thumbnail_id = get_post_thumbnail_id( $post->ID );
$thumbnail_attributes = wp_get_attachment_image_src( $post_thumbnail_id, 'twentyseventeen-featured-image' );
?>
<div class="custom-header-image" style="background-image: url(<?php echo esc_url( $thumbnail_attributes[0] ); ?>)"></div>
<?php get_template_part( 'components/header/site', 'branding' ); ?>
<?php else : ?>
<?php // Otherwise, show a blank header. ?>
<div class="custom-header-simple">

View File

@ -11,6 +11,23 @@
?>
<article id="post-<?php the_ID(); ?>" <?php post_class( 'twentyseventeen-panel ' ); ?> >
<?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; ?>
<div class="panel-content">
<div class="wrap">
<header class="entry-header">

View File

@ -34,8 +34,8 @@ function twentyseventeen_body_classes( $classes ) {
$classes[] = 'twentyseventeen-front-page';
}
// Add a class if there is a featured image or custom header.
if ( has_header_image() || ( has_post_thumbnail() && twentyseventeen_is_frontpage() ) ) {
// Add a class if there is a custom header.
if ( has_header_image() ) {
$classes[] = 'has-header-image';
}

View File

@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.7-alpha-38867';
$wp_version = '4.7-alpha-38868';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.