In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-11 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
Today, I will talk to you about how to create a custom page template in WordPress. Many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
WordPress page templates are specific template files for specific pages or page groups, and these templates for single-page data are displayed at the front end. We can also create custom page templates in WordPress.
Create a custom page template in WordPress
By default, WordPress allows you to use the default template file page.php to create pages and articles to handle the appearance of the front end.
We can also make changes to the default template file (page.php), but these changes affect all other pages that you have created.
So, that's why we need to create a custom page template in WordPress to handle specific page layout designs according to requirements.
Let's start by creating a custom page template.
To start creating custom templates, you only need basic knowledge of HTML, CSS, and PHP. Of course, I also need a favorite file editor, which I often use is Sublime Text.
Therefore, open the file editor and paste the following code into it.
Save this file with the name "my-custom-page-template.php". You can change the file name as needed. But don't forget to save the extension as .php.
The annotated file above tells WordPress that this is a template file and that you provided the template name. When we create a new page, it will be displayed in the page properties section under the template drop-down menu. We'll see it below.
Now we are going to upload this file to my host, where we host our WordPress website. Then we will test whether the file works.
There are two ways to upload files:
Use cPanel and File Manager to use FTP (File transfer Protocol) accounts
Here, I'll show you using the FTP application FileZilla. Let's open FileZilla and log in with my FTP account details.
Navigate to this path "/ wp-content/themes/ACTIVETHEME" folder. ACTIVETHEME is the placeholder for the currently active theme. I would recommend that you choose a child theme of the parent theme. If you don't have a subtheme, see how this article makes a subtheme in WordPress. .
So, we are on the current active theme. Now upload the file to this folder. Check the following figure to understand.
Compare this image with what you have done. So we can continue to test the file by creating a new page.
So now go to your WordPress dashboard and click New Page under the Page option in the sidebar. You will see the template displayed under the properties section of the page.
Add a new title to the page and select the custom page template from the drop-down list and publish the page.
Now, open the page at the front end. You will see a blank page because we have not done anything for this template.
Let's add some code to the template file to display on the front end. Add the following line to the file. These functions will display the default header Header, footer Footer, and sidebar Sidebar.
/ * your custom code here*/
The following code loops through post_type = > post and displays the article title and content of all articles. I use the the_title () function to display the article title and the the_content () function to display the article content.
There are more functions, such as:
The_title ()
The_content ()
The_post_thumbnail ()
The_permalink ()
The_excerpt ()
The_time ()
The_author ()
The_category ()
Save this code in your template file, and it will display all the articles on the page at the front end, and you can design it according to your design layout to make it look and feel better.
You can also add your own custom code according to your requirements and do the following:
Create different headers and footers
Customize the layout according to your PSD/ wireframe template
Custom sidebar location or can be deleted
Show specific article types for specific conditions
You can do more on this custom page template. Just think about and execute your custom code.
That's it. You have completed customizing the page template in WordPress.
After reading the above, do you have any further understanding of how to create a custom page template in WordPress? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.