Question

Bear with me as i try to learn WP.

Lets say we have a 3rd party theme were the route of the request is somehow like this.

Root theme index.php diverts to a nother php file which decides what page to go next depending on the themes settings.

then it gets diverted to a master page that handles all kind of pages (posts,pages,archives) using logic within this file.

And now Native WordPress comes and says for example that you can just create a category-{slug}.php file and use it.

It seems to work this way if i put a simple category-{slug}.php in my themes ROOT directory.

So is this how everything is working in WP? I can make a child theme for my paid theme and go inside and everything that codex says?

Maybe i am not well understood , but if someone "catches" my thinking , i would appreciate a shed of light.

Was it helpful?

Solution

Do not rely on the codex. Some pages are just a heap of crap and totally useless. The problem with the codex is that everybody with an account on wordpress.org can change and alter the codex as they see fit.

I don't say, Do not use the codex, I'm saying that you need to be cautious. You need to read the codex in conjuction with the actual source code. Some pages are very well written and clear with many good examples of usage.

The way I read your question, you are hinting on the Template Hierarchy. This is one of the most important section as this is how Wordpress decides which template to serve up according to the URL been served. These templates are the recommended ones and any template naming convention outside this hierarchy won't work out of the box. Also, any naming convention that creates conflict with these set hierarchy will be ignored and will fail.

There are filters like template_include and single-template which will allow you to set a custom template which is outside normal hierarchy rules according to your needs. For example, if you need a custom template for the single posts of a specific category, you can create a file called single-cat.php and then use the single_template filter to tell Wordpress to use this template whenever a single post is from this specific category

EDIT

From comments, it is really easy to create any template in your theme. index.php can used as a base for any template. You just need to make a copy of index.php and rename it to what is needed

For eaxample, if your theme don't have a category.php, you can simply copy index.php and rename it to category.php

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top