• Hello, I have a nice structure going with my page.php. I have a title and the featured image displaying how I want. However, when I go to reading -> make post page the page I want, the title and featured image disappear.

    The next logical step is that it changes that page to index.php right? I go and put the stuff from page.php I want ( featured image and title html and css ) and it’s still not showing up.

    Am I missing something?

    index.php

    <?php get_header('main'); ?>
    
    	<main role="main">
    		<div class="page-section clear">
    			<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>
    		</div>
    		<!-- 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(); ?>
Viewing 2 replies - 1 through 2 (of 2 total)
  • if the posts page is used, it has teh ID of get_option( ‘page_for_posts’ ) which you can use to get the page title and the page featured imnage;

    example code for index.php (untested)):

    <?php
    if( is_home() && get_option( 'page_for_posts' ) ) {
      $posts_page = get_page( get_option( 'page_for_posts' );
      $title = apply_filter( 'the_title', $posts_page->post_title );
        if ( has_post_thumbnail( $posts_page->ID ) ) {
        $image = wp_get_attachment_image_src( get_post_thumbnail_id( $posts_page->ID ), 'single-post-thumbnail' ); ?>
        }
    }
    ?>

    you need to adapt the html structure yourself.

    Thread Starter txwrang

    (@txwrang)

    Do you mind explaining that a little further? “if the post page is used” Used where? Which post page?

    You’re saying that if I make a page I created, in this case a normal page called blog, and I’m making it the post page, it automatically becomes a different page with different ID’s? Or what is happening here? Also not sure what you put If( is home()

    . I”m looking for an a solution to my problem, but I would love to understand it as well. Fairly new with WordPress. Thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get title and featured image to show up’ is closed to new replies.