0

So I have created an archive.php, set everything up, and my archive page works fine.

Now I was wondering, of how I should prevent the archive page from listing itself.

When accessing the page called archive for instance https://domain.com/archive, without any date/category parameters set, the query of the archive page is itself, like on a normal page. So the WP Loop will of course check has_posts etc. and the list itself, but I want to add something like the latest posts if there are no "filters" applied.

Anyone got an idea?

6
  • I'm not sure how you've set up your archive. WordPress generates an archive for you, which you can assign to a page to under your settings. It'll show posts in chronological order from latest onward by default.
    – Milo
    Commented Jan 27, 2019 at 20:04
  • Yes, the archive page template is assigned to a page called archive. When I access that page without any parameters, like a date or category, it lists it self with the loop, but when accessing the page with parameters, the list shows all the posts of those parameters
    – josias
    Commented Jan 27, 2019 at 20:08
  • archive.php isn't a template you manually assign to a page, it's the template WordPress automatically uses when you set your page as the archive under Settings > Reading > Posts page.
    – Milo
    Commented Jan 27, 2019 at 20:23
  • In that case I don't quite understand, why it should appear in the template dropdown when editing a page. If it's not supposed to be assigned to a page, why is it a template?
    – josias
    Commented Jan 27, 2019 at 20:28
  • 1
    Because it has a template header at the top of the file that WordPress detects, which are not intended for that kind of template. Have a look at the Template Hierarchy to see all of the templates WordPress automatically uses for each type of request. These are different from custom page templates you create for manual assignment.
    – Milo
    Commented Jan 27, 2019 at 20:34

1 Answer 1

0

As @Milo told me in the comments, the problem lies in the fact, that the archive template shouldn't be applied to a page, but left untouched.

That way WordPress will still know which template to use for displaying an archive but you can't access the template itself, which means it will not display itself in the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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