Support » Plugin: Gutenberg » How do I put my frontpage featured image in a page template for home.php?

  • Resolved Jackalope Co.

    (@thedonquixotic)


    Explanation of Question:

    I’m working on building a new theme for a simple portfolio website. I want it to use Gutenberg as much as possible and to use as few other plugins as possible.

    I have created a home.php file. I have also designated it as a theme using the following code:

    ` <?php
    /**
    * Template Name: Home
    *
    * Description: A custom template for the front page
    *
    * @package JackalopePro
    * @version 1.5
    */`

    When I go to the “Pages” section of the Admin Panel I can correctly see “Home” in my options of page templates when creating a new page in Gutenberg. I can set content, title, featured image etc, and publish. (this will page created in the admin panel will be referred to as FrontPage-G)

    When I add <p> this is the home template</p> to my home.php file I can see that upon previewing the FrontPage-G. I can see it when I load my website from it’s root or default page etc. So the template is correctly being read as the necessary template file for the page that was created in Gutenberg, AND it’s being correctly read as the page which the frontpage of the website should be using.

    BUT

    It does not load the featured image, or content/title when I call get_post_thumbnail();

    My frontpage should be structured like this:
    (structure written in pseudo code obviously)

        <Nav></Nav>
        <FrontpageFeaturedImage></FrontpageFeaturedImage>
        (The following is a wp query loop for all the blog posts)
        <Post>
          <ThePostFeaturedImage></ThePostFeaturedImage>
          <ThePostTitle></ThePostTitle>
          <ThePostExcerpt></ThePostExerpt>
        </Post>
        <Post>
          <ThePostFeaturedImage></ThePostFeaturedImage>
          <ThePostTitle></ThePostTitle>
          <ThePostExcerpt></ThePostExerpt>
        </Post>
        <Post>
          <ThePostFeaturedImage></ThePostFeaturedImage>
          <ThePostTitle></ThePostTitle>
          <ThePostExcerpt></ThePostExerpt>
        </Post>
        <Post>
          <ThePostFeaturedImage></ThePostFeaturedImage>
          <ThePostTitle></ThePostTitle>
          <ThePostExcerpt></ThePostExerpt>
        </Post>
        <Post>
          <ThePostFeaturedImage></ThePostFeaturedImage>
          <ThePostTitle></ThePostTitle>
          <ThePostExcerpt></ThePostExerpt>
        </Post>
        <Footer></Footer>

    When I visit my frontpage, it shows a Hero Image for the frontpage but instead of it being the Featured Image that I assigned in the the Frontpage-G page in Gutenberg, it’s just the first featured image of my blog posts (so in other words you see the image for the first blog post twice on that page).

    When I try to check it through the “view page” of Frontpage-G it either shows me nothing, or it shows me a page in which there is the correct Featured Image as the frontpage Hero Image, but then underneath it, instead of having the rest of the blog posts from the page, it has a single post, and it has just the information from the page that I am trying to use as my frontpage, Frontpage-G.

    Is it possible for me to edit or change my frontpage using Gutenberg? If I want to have a frontpage with a featured Image and Title can I change that using Gutenberg or do I have to resort to using ACF or something of that sort?

Viewing 1 replies (of 1 total)
  • Hi!

    I know that this reply might come too late, but, if you are still looking for a solution, you can first try renaming home.php to something else.
    Home.php is a reserved file name in the template hierarchy, and is not intended to be used for a custom page template.

    The template file home.php is used to render the blog posts index, whether it is being used as the front page or on separate static page.

    You can read more about the template hierarchy here:
    https://developer.wordpress.org/themes/basics/template-hierarchy/#home-page-display

Viewing 1 replies (of 1 total)
  • The topic ‘How do I put my frontpage featured image in a page template for home.php?’ is closed to new replies.