I am trying to find the feature to add a page template. I am adding an archive but when I go into pages->Add New-> I get no option in the sidebar to use the existing archives.php file I want to use. Can anyone help me out?
1 Answer
archives.php
is a template file that WordPress will use by default (if it exists). If you want to create a custom page template you need to create a new template file in your theme. You can read all about it in the Codex, but I'll provide an example below. Put this at the top of your new file:
<?php
/*
Template Name: Your page template name goes here.
*/
?>
Then follow it with the custom code you need to display your data.
Then, when creating a new page that you would like to use the above template, you will see a drop-down list on the right that lists all the names of page templates you have in your theme.
-
I already have code similar to this in my style.css file. I created a theme from scratch and applied my CSS to it. i Created a custom archives.php file yet it doesn't display in the dashboard to allow me to select it as a template– NATHAN CCommented Mar 13, 2012 at 20:23
-
+1 See also: the Codex entry for custom Page templates. Commented Mar 13, 2012 at 20:24
-
"I already have code similar to this in my style.css file." - It's not what's in your
style.css
file that matters, but rather the phpDoc header inarchives.php
. Commented Mar 13, 2012 at 20:25 -
The above code does not go in your stylesheet, it HAS to go at the top of your custom page template. Archives.php is a file name that is reserved by WordPress. If you want to use that same file, simply rename page-archives.php and it should work.– cmegownCommented Mar 13, 2012 at 20:25
-
2Actually,
archives.php
is not reserved; that would bearchive.php
. Though, I would still recommend using something liketemplate-archives.php
as your custom Page template file name. (I would not usepage-archives.php
, aspage-{slug}.php
is reserved by the Template Hierarchy. Commented Mar 13, 2012 at 20:28