What is Page Template
Page template in WordPress are a great way to add structural variations or highly customized functional to your website. Page templates are a specific type of template file that can be applied to a specific page or groups of pages.
here are some distinguishing features of page templates:
- Page templates are used to change the look and feel of a page.
- A page template can be applied to a single page or a custom page.
- Page templates generally have a high level of specificity, targeting an individual page or group of pages. For example, a page template named page-about.php is more specific than the template files page.php or index.php as it will only affect a page with the slug of “about.”
- If a page template has a template name, WordPress users editing the page have control over what template will be used to render the page.
for more details:https://developer.wordpress.org/themes/template-files-section/page-template-files/
Creating Custom Page Template
In this section, Will going to add/create a WordPress page template in our theme to implement a specific design to your page.
To create a page template, write an opening PHP comment at the top of the file that states the template’s name. ( see image below )
It’s a good idea to choose a name that describes what the template does as the name is visible to WordPress users when they are editing the page. For example, you could name your template Homepage, Blog, Portfolio and Front-page.
- Create a file under your theme’s folder ( e.g. page-templates.php )
- Add the following code/comment just like the image below to set a template name.
- Save the file
- Create a page to apply this Custom page template
- Edit the page you created ( page > Edit ).
- On the right hand under Page Attributes you’ll see template. This is where you can select the template name you’ve created which is ‘My Custom Page’ to set the custom page template in a page. see image below.
Now you have a working custom page template but for now this is an empty page. You can now add your custom HTML and CSS to meet the design, look and feel of your custom page. ( see image below )
Save the file.
Go to WordPress admin and Pages.
Click View button to preview your custom page.
Uses of Page Templates
Page template display your site’s dynamic content on a page. e.g., posts, news updates, events etc. This is where page templates come into play. Customized page templates allow you to tweak a specific design of your wordPress site without affecting the rest of it.
Register Your Custom Post Type
The next step deals with WordPress standard custom post type registration. In this part we will register the custom post type name PORTFOLIO.
for more information on registering custom post types and custom taxonomies, seehttps://codex.wordpress.org/Function_Reference/register_post_type
- Go to your WordPress Theme Folder
- Look for Function.php File
- add the following code below.
- Save the file.
- Go to your WordPress admin you’ll see the custom post type. under the Post link.
- Clink Portfolio to add some post add publish.
CONGRATS! You now have a newly created custom post type, You can now start adding some portfolio as a individual posts.