I need to create some new pages for my website e.g. Gallery, Audio collection, etc. I want them to have a layout similar to my theme's index.php. How can I do this so that the layout updates for the mentioned pages if I change current theme for my WordPress website?
Do I have to use the same markup of index.php in new pages I want to create or is there a systematic way to tell WordPress to use the same layout for my theme's index.php for my new pages?
1 Answer
Wordpress loads templates in order from most specific to least specific, depending on which templates files exists.
For instance, lets say we have a wordpress page by name of "Audio Collection" with page ID of 14. WordPress would look for files by these names in order, and return the template for the first file name it checks that exists in your active theme.
- page-audio-collection.php
- page-14.php
- page.php
- index.php
So if you wanted to, you could create a duplicate of index.php, and call it page-audio-collection.php, and modify it as needed. That template would only be loaded when viewing the Audio Collection page, and all other pages would continue loading their current template file.
You could also create and assign a Custom Page Template, which would override all of the normal template hierarchy I outlined above.
read more at WordPress Template Hierarchy
-
Thanks @Matt-keys. Can I use a single page.php for all the pages of image gallery, audio gallery, video gallery, etc.? If so, what code should I use inside page.php to query relevant page content (audio gallery, image gallery, etc.) I created within admin panel? Commented Nov 8, 2014 at 16:48
-
If you have multiple pages that you want to use the same template, then it would be best to use a Custom Page Template These can be created in your active theme, then you can assign multiple pages to the same template. Commented Nov 8, 2014 at 16:57
-
Given the fact that get_page() is deprecated, how should I query a page? Commented Nov 8, 2014 at 16:58
-
One other important thing I am confused with is what to use as hyperlink for these new created pages in my main template's menu HREFs, so that clicking the links will open relevant pages with the same template for all. Commented Nov 8, 2014 at 17:11
-
Checkout the WordPress Codex for some of the answer you are looking for here. Specifically read up on permalinks. Your question about get_page should probably be submitted as a new question with some code examples of what you have tried so far and what you are trying to accomplish. Commented Nov 8, 2014 at 17:49