posts - Why is my custom template not showing anything?

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

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744740255a4590984.html

相关推荐

  • posts - Why is my custom template not showing anything?

    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

    19小时前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信