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.


git-svn-id: https://develop.svn.wordpress.org/trunk@38868 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
David A. Kennedy 2016-10-21 22:14:26 +00:00
parent 4b9833b656
commit 67d767514e
3 changed files with 19 additions and 11 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';
}