admin管理员组

文章数量:1410697

I'm building a theme and I've found it all pretty simple and straightforward.

However, I can't figure out why I have a totally blank page for my archive WordPress blog posts?

I understand the WordPress Hierarchy and I have a page called:

archive.php

This is my code on that page:

    <?php get_header();?>

    <div class="container">

      <h1><?php echo single_cat_title();?></h1>

      <?php if( have_posts() ): while ( have_posts() ): the_post();?>

<div class="card">
  <div class="card-body">
    <h3><?php the_title();?></h3>

    <?php the_excerpt();?>

    <a href="<?php the_permalink();?>" class="btn btn-success"> read more</a>
  </div>
</div>

<?php endwhile; else: endif;?>

      <?php previous_posts_link();?>
      <?php next_posts_link();?>

    </div>

    <?php get_footer();?>

And when I view that page view a browser, i.e. my designated "blog page" in WordPress (selected in "Reading") I see nothing, totally blank, there is even no source to view.

Any idea on what (basic) error I am making here....

Thanks

I'm building a theme and I've found it all pretty simple and straightforward.

However, I can't figure out why I have a totally blank page for my archive WordPress blog posts?

I understand the WordPress Hierarchy and I have a page called:

archive.php

This is my code on that page:

    <?php get_header();?>

    <div class="container">

      <h1><?php echo single_cat_title();?></h1>

      <?php if( have_posts() ): while ( have_posts() ): the_post();?>

<div class="card">
  <div class="card-body">
    <h3><?php the_title();?></h3>

    <?php the_excerpt();?>

    <a href="<?php the_permalink();?>" class="btn btn-success"> read more</a>
  </div>
</div>

<?php endwhile; else: endif;?>

      <?php previous_posts_link();?>
      <?php next_posts_link();?>

    </div>

    <?php get_footer();?>

And when I view that page view a browser, i.e. my designated "blog page" in WordPress (selected in "Reading") I see nothing, totally blank, there is even no source to view.

Any idea on what (basic) error I am making here....

Thanks

Share Improve this question asked Dec 16, 2019 at 22:05 HenryHenry 9831 gold badge8 silver badges31 bronze badges 2
  • 1 archive.php is not used for Pages, even if you have set one as the "blog page." Try renaming your file page-slug.php - i.e. if the Page is at example/my-page, the slug is "my-page", so name the file page-my-page.php - that way your template will apply to the Page you've created. – WebElaine Commented Dec 16, 2019 at 22:09
  • Hmm, I'm a bit confused though because what I am trying to do is just loop the blog posts - that's it. What am I missing? What is the "generic" WP hierarchical page that will list blog posts then? – Henry Commented Dec 16, 2019 at 22:29
Add a comment  | 

1 Answer 1

Reset to default 4

Your designated 'blog page' (selected in 'Reading') will use the index.php file (or home.php) rather than archive.php file.

本文标签: hierarchicalArchive page showing nothingissue with WordPress Hierarchy