0
votes

In 'Reading Settings' I have chosen the static-page drop-down menu of a page I created to be the post page.

I've put the html, php, and css from my page.php in index.php to style it. I'm unable to get the featured image. The php I use to get it on page.php isn't working. It's not rendering any html. Also <?php the_title(); ?> is pulling up the title of the most recent blog post, not the page title of the page I have switched over.

This is how I'm generating my featured image on page.php.

            <div class="single-image-anchor">
                <?php if (has_post_thumbnail( $post->ID ) ): ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( $post->ID ), 'single-post-thumbnail' ); ?>
                <div class="single-image" style="background-image: url('<?php echo $image[0]; ?>')">
                <?php endif; ?>
            </div>

Here is the code to my original index.php

<?php get_header('header-main'); ?>

    <main role="main">
        <!-- section -->
        <section>

            <h1><?php _e( 'Latest Posts', 'html5blank' ); ?></h1>

            <?php get_template_part('loop'); ?>

            <?php get_template_part('pagination'); ?>

        </section>
        <!-- /section -->
    </main>

<?php get_sidebar(); ?>

<?php get_footer(); ?>

I am fairly new to Wordpress so thanks in advance.

1
@sdcr see edits. Thanksuser2684452
That adds the featured image of THE POST which is awesome and greatly appreciated, but I'm trying to add the featured image of the PAGE that now hosts the blog loop.user2684452
just edited my comment, see aboveuser2684452

1 Answers

0
votes
             <div class="page-section clear">
                <div class="single-image-anchor">
                <?php if (get_option( 'page_for_posts' ) ): ?>
                <?php $image = wp_get_attachment_image_src( get_post_thumbnail_id( get_option( 'page_for_posts' )), 'single-post-thumbnail' ); ?>
                <div class="single-image" style="background-image: url('<?php echo $image[0]; ?>')">
                <?php endif; ?>
                </div>
            </div>
        <h1 class='title'><?php if(get_option( 'page_for_posts' ) ) echo get_the_title( get_option( 'page_for_posts' ) ); ?> </h2>
        <h1><?php _e( 'Latest Posts', 'html5blank' ); ?></h1>