最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

loop - Archive: Lists itself

matteradmin9PV0评论

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 , 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?

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/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?

Share Improve this question asked Jan 27, 2019 at 19:40 josiasjosias 1959 bronze badges 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
 |  Show 1 more comment

1 Answer 1

Reset to default 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.

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far