0

I'm trying to build my first custom theme by watching some tutorials and tips.

So I have the index, custom pages, and I tried to make the "archive" page and it redirects to my index. The file "archive.php" is there, and in the Reading Settings I requested that the "Blog" page (created in the Pages menu) receive the posts.

How to proceed?

enter image description here enter image description here

archive.php

<?php get_header(); ?>
<section id="content">
    Testing 123
</section>
<?php get_footer(); ?>
1

If you're using a static page as your front page (as shown in your first image), then neither archive.php or home.php will work. The page hierarchy for static home pages is:

  1. Page Template
  2. page-{slug}.php
  3. page-{id}.php
  4. page.php
  5. index.php

If you want to show an archive on your front page, select 'your latest posts', then home.php will work.

In either case, front-page.php will be the first in the hierarchy.

  • Hey @Nathan Johnson, thanks. But i dont want to show my archive in my front page. I want to show the archive when access the "localhost/blog". – Maykel Esser Jan 27 '17 at 11:42
0

You should use home.php file instead of index.php, this is the Wp template hierarchy structure

UPDATE:

Your archive file should be like this:

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

    <article class="<?php post_class(); ?>">
        <h1><?php the_title(); ?></h1>
        <div class="post-content">
            <?php the_content(); ?>
        </div>
        <a href="<?php the_permalink(); ?>">Read more</a>
    </article>
<?php endwhile; // end of the loop. ?>
<?php get_footer(); ?>
  • I've tried to rename my index to "home.php", but, nothing happens. – Maykel Esser Jan 26 '17 at 17:32
  • You don't have to rename it, you should have most of those files in your theme folder, if you are developing your own theme you should create them. single.php, page.php, home.php, front-page.php, archive.php and so on you can also create archive-custom-post-type.php if you have custom post types. – Al Rosado Jan 26 '17 at 20:02
  • your archive should aldo be like this: – Al Rosado Jan 26 '17 at 20:26
  • thank you. My archive file is almost exactly as you showed it. My dir structure: i.imgur.com/7TvxQUe.png ` <?php get_header(); ?> <?php while ( have_posts() ) : the_post(); ?> <div class="container"> <h1><?php the_title(); ?></h1> <div class="post-content"> <?php the_content(); ?> </div> <a href="<?php the_permalink(); ?>">More!</a> </div> <?php endwhile; ?> <?php get_footer(); ?>` – Maykel Esser Jan 27 '17 at 11:47
  • I'm not understanding what I'm doing wrong. Is my file structure/settings incorrect? – Maykel Esser Jan 27 '17 at 11:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.