admin管理员组

文章数量:1389772

UPDATE 1: I tried creating a new page and the header and footer is showing, but not the posts. UPDATE 2: If I update the Reading settings to Post page and select the page I created with the custom template, nothing is showing.

<?php /* Template Name: Blog Template */ ?>

<?php get_header(); ?>

<h1>Blog posts</h1>

<div class="container">
    <?php while(have_posts()): the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
</div>

<?php get_footer(); ?>

UPDATE 1: I tried creating a new page and the header and footer is showing, but not the posts. UPDATE 2: If I update the Reading settings to Post page and select the page I created with the custom template, nothing is showing.

<?php /* Template Name: Blog Template */ ?>

<?php get_header(); ?>

<h1>Blog posts</h1>

<div class="container">
    <?php while(have_posts()): the_post(); ?>
    <?php the_content(); ?>
    <?php endwhile; ?>
</div>

<?php get_footer(); ?>
Share Improve this question edited Feb 18, 2020 at 3:08 Cypher asked Feb 18, 2020 at 2:54 CypherCypher 451 silver badge5 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

The template for displaying all your posts should not be a custom page template. You should set the page you want to use as your Posts page in Settings > Reading. Then, as per the Template Hierarchy, your theme will automatically use home.php for this page, or index.php if that does not exist.

So you should save your template as home.php, without the /* Template Name: Blog Template */ comment, and set the page you want to use for displaying posts in Settings > Reading.

本文标签: postsWhy is my custom template not showing anything