At the moment I'm using multiple page templates to display custom posts (page-events.php, page-resources.php) and it seems wasteful.

How can I reuse page.php and just display the post type relating to the page a user has clicked on?


  • 1
    It sounds like you're using page templates incorrectly. Is page-events.php for a single event, or a list of events? See the template hierarchy for how WordPress decides which template to use. If you have pages that are lists of posts in a custom post type, then that should be an archive and use the appropriate template. – Jacob Peattie Apr 2 at 10:31
  • It's a list of events (or resources or programmes), which you can click to go to a single event (which I've yet to implement). So if I use an archive, should I create just one for all post types or one archive for each? And if it's possible to display posts based on type, from one template, any ideas where to look/what to search for? – JakePowell Apr 2 at 10:49
  • This is all stuff WordPress does automatically. You don't create pages for archives, you just register the post type and the archive URL is created automatically. The template hierarchy, which I linked, decides which template file gets used, but all the templates should use the standard loop. I suggest reading through the Theme Developer Handbook. – Jacob Peattie Apr 2 at 10:54
  • Ok thanks, I'll get reading – JakePowell Apr 2 at 11:00

Your Answer

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

Browse other questions tagged or ask your own question.