Further the last WordPress Beirut meetup we had in the 1st of August 2017 at BDD (details here), this article covers all points we discussed in the presentation titled “When you should develop a WordPress theme from scratch?“.
Ideally, I was planning to cover all below 14 topics in my presentation:
-
- When you shouldn’t develop a WordPress theme from scratch? What alternatives do you have?
- Basic template files execution
- Basic template files structure
- WordPress files structure
- Template Dos and Don’ts
- A look to WordPress database structure
- Securing WordPress files (naming and files permissions)
- Customizing WordPress CMS
- Additional WordPress features you can use
- WordPress plugins we use
Michel:
- Setting up test environments
- How to create custom post types, pages, and taxonomies
Bonus: How we made WordPress easier for our VOD websites
However, due to continuous interactions and discussions we only managed to go through:
- When you should develop a WordPress theme from scratch?
- When you shouldn’t develop a WordPress theme from scratch? What alternatives do you have?
- Basic template files execution
I’ll try to cover all the above points throughout this post, thus I’ll make sure to update new posts regularly whenever we have the chance to continue the presentation in the upcoming meetups. (Presentations posts can be accessed through here).
When you should develop a WordPress theme from scratch?
WordPress themes are categorized into 2 main types, pre-developed and custom.
Pre-developed themes are themes you can get free from wordpress.org/themes or themes you can buy from a large variety of resources (such as themeforest), it’s also known as premium themes.
Custom themes are themes developed from scratch including all theme aspects, functionality and pages. Hence, it has several benefits:
- Offers more customization
- Is more valuable since the written code is unique
- The options are endless and the developer doesn’t have to stick to options offered by the chosen theme
- Has cleaner code
- WAY easier to modify/update/debug
- Allows multiple developers to work together
- Developing specific options from scratch can sometimes be easier than finding turnarounds for pre-developed themes
When you shouldn’t develop a WordPress theme from scratch? What alternatives do you have?
Custom themes required a lot more efforts than pre-developed themes including:
- Frontend design
- UI/UX design
- Frontend development
- Backend development
- In some cases, database structure design
These tasks requires more resources and usually costs a lot more money.
Alternatives can be:
- Working with WordPress free themes (https://wordpress.org/themes/)
- Buying premium WordPress themes (http://themeforest.com)
- Not using CMS based solutions (HTML templates, writing flat php, using alternative php frameworks such as laravel, codeigniter… )
Basic template files execution
Home Page
This is the first and most important page of any website. So WordPress has provided the scope to customize the page. Let’s have a look at the file hierarchy for the home page.
- front-page.php
- home.php
- index.php
While serving the home page, WordPress will search for front-page.php. If that is not found, it will use home.php. If home.php exists, it’ll use that. If not, it will simply default to using index.php.
WordPress Post Detail
- single-[post-type].php
- single.php
- index.php
WordPress can have as many post types as we need. So this will be easier to get different design for all/some post types. By default ‘post’ is the main and default post type of the WordPress.
So for example, if your custom post type is product then it will be single-product.php
To know more how to add new post types in WordPress you can refer to this link.
WordPress Page Detail
- [custom-template].php
- page-[slug].php
- page-[id].php
- page.php
- index.php
Just the same as with post types, we can have a different page layout using the custom page template. So WordPress first searches for the files of the selected Page template (if it exists).
If none are found, it will search for the file with the slug of the current page. Basically, if the slug is aboutus, then it will search for the file page-aboutus.php in active theme folder.
WordPress will search for the files with the ID just like searching for the files with slug.
Category Page
- category-[slug].php
- category-[id].php
- category.php
- archive.php
- index.php
From the above flow, you can understand that how you can have different templates used for the category page. For instance, you could have a custom page based on slug and id, and then use a default “category.php” file for the rest of your categories..
Tag Page
- tag-[slug].php
- tag-[id].php
- tag.php
- archive.php
- index.php
This will be same case as the category. You can have different pages for tag slug and tag id also.
Taxonomy Page
- taxonomy-[tax]-[term].php
- taxonomy-[tax].php
- taxonomy.php
- archive.php
- index.php
Here goes the different file hierarchy for the taxonomy Pages.
Author Page
- author-[author-nicname].php
- author-[author-id].php
- author.php
- archive.php
- index.php
Here you come to know that you can have different designs based on users also. Same as category and tags we can have different files based on slug and ID of the user.
Attachment Page
- [mime-type].php
- attachment.php
- single.php
- index.php
Here you can see that you can have different page layout for different types of attachment. These can be differentiate from the mime type of the attached file.
Date Page
- date.php
- archive.php
- index.php
For the date specific layout we can create date.php in theme folder. Then the flow goes to archive.php and then at last index.php.
Archive Page
- archive.php
- index.php
As we come downwards to the type of files, number of files are reduced in the hierarchy. So this are the basic or we can say most used files in any WordPress themes.
Search Page
- search.php
- index.php
You can customize your search result with the search.php first. If search.php is not available then index.php will be served.
404 Page
- 404.php
- index.php
In the case of page or post not found, WordPress will search for 404.php then if not found then it will serve index.php.
Resource: Code.tutplus.com post
Stay tuned for more updates in upcoming presentations,
Happy coding!
I’m a coding fan, open source contributor, occasional writer at blog.maroun.me