You are currently viewing Project one

Project one

My understanding from reading the WP template hierachy was that when I set my a page as my posts page in settings > reading settings that WordPress should use archive.php. Instead it uses index.php.

Obviously I could just put my code in index.php and my site will work. But it doesn’t seem like best practice, and I can’t find any documentation of best (or good) practice. Why doesn’t WordPress use archive.php in this circumstance? And would using index.php as my posts page have unintended consequences? Among the most important tools in the quest for complete website control are page templates. They allow users to dramatically alter their website’s design and functionality. Want a customized header for your front page? Done. An additional sidebar only for your blog page? No problem. A unique 404 error page? Be. My. Guest. If you want to know how WordPress page templates can help you achieve that, read on. But first, a little background information.

Note: I’ve been using the _s theme as a base, but I’ve had the same problem with no theme base or parent.

Creating a Custom Page Template for One Specific Page #Creating a Custom Page Template for One Specific Page

As mentioned in the Template Hierarchy page, you can create a template for a specific page.  To create a template for one specific page, copy your existing page.php file and rename it with your page’s slug or ID:

  1. page-{slug}.php
  2. page-{ID}.php

For example: Your About page has a slug of ‘about’ and an ID of 6. If your active theme’s folder has a file named page-about.php or page-6.php, then WordPress will automatically find and use that file to render the About page.

To be used, specialized page templates must be in your theme’s folder (i.e. /wp-content/themes/my-theme-name/ ).

Leave a Reply