I have a solution to this problem, but am not ecstatic about it (it doesn’t use a WP function to obtain the URL of the Featured Image (and, in fact, because of that, I removed the featured image from the posts page).
I copied the twentyseventeen header.php file to my child theme. In that file, twentyseventeen has the following code:
<?php
// If a regular post or page, and not the front page, show the featured image.
if ( has_post_thumbnail() && ( is_single() || ( is_page() && ! twentyseventeen_is_frontpage() ) ) ) :
echo '<div class="single-featured-image-header">';
the_post_thumbnail( 'twentyseventeen-featured-image' );
echo '</div><!-- .single-featured-image-header -->';
endif;
?>
Just after the opening PHP tag, I inserted the following code:
// 2017-05-15 JRG show featured image on home page
if ( is_home() && ! is_front_page() ):
echo '<div class="single-featured-image-header">';
echo '<img src="https://cornerstonehousingsociety.org/wp-content/uploads/2017/05/news.png" alt="" class="aligncenter" />';
echo '</div><!-- .single-featured-image-header -->';
endif;
The twentyseventeen code uses the function has_post_thumbnail() which fails rather miserably when invoked on the posts page (and it doesn’t work when a single post is being displayed, which it appears intended to do). Note: the function twentyseventeen_is_frontpage() is a test for the “front page”, excluding the “home page”. The test I coded is almost the opposite (the home page unless it is the front page).
Forgot to mention: The URL in my code is just a test site. Obviously, if you want to use this code yourself, you would need to use an appropriate URL for your img tag “src”.
-
This reply was modified 7 years, 6 months ago by johngoold. Reason: Afterthought