Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have created a new template page and added to the theme's directory where the other pages, archive, comment, author and the rest of the pages are. When trying to go to it via the browser http://mysite.com/newpage.php, I get a 404 page not found error.

What is the proper way to add this page so it is visible and as part of the theme instead of adding it to the root?

share|improve this question

2 Answers 2

Page templates don't work that way.

The way they work is that you create a normal Page, and then select your custom Page Template to display it with. The URL of the resulting Page is determined by the permalink structure and slug you selected.

share|improve this answer

Templates are not meant to be static pages - the templates are included() when the uri accesses some resource - be that an archive or a specific post/page.

There are two main ways a template gets selected to represent a resource.

  1. Page Templates
  2. Template Hierarchy

When using the Page Template method, you need to specify the correct comments at the top of the template, to inform WordPress that you want this template to be available as a "Page Template". Once that is there, go and create an actual Page in WordPress (by this I mean, a content object of the post_type "page"). Once you have that, you should be able to see a dropdown in the page editor, labeled "Template" from which you can select the template.

Using the Template Hierarchy you would name with the slug or id of the page in he name. This would make the page come up for only that page. Otherwise just naming it page.php would make any page use that template.

There is a third option - which is to intercept the template hierarchy and make it work to your liking. Additionally you can use custom uris to hit specific templates by adding custom rewrite rules and query vars. I wont go into that unless you specifically request that.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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