I want a post have the template of the parent category.. Is that possible? if yes, please guide me a bit. Or if any plugin is available, name it.
Leave a Reply
You must be logged in to post a comment.
I want a post have the template of the parent category.. Is that possible? if yes, please guide me a bit. Or if any plugin is available, name it.
You must be logged in to post a comment.
As of WordPress 3.0, the logic in
wp-includes/template-loader.php
for selecting a template looks like this:Checking
get_category_template()
in wp-includes/theme.php` we see:Assuming that your category is
Foo
, that it’s slug isfoo
, and that theFoo
category ID is17
, for a post that belongs to categoryFoo
, WordPress will check for the following templates in your theme and use the first one it finds:Thus, all you should need to do is to create a template named
category-foo.php
in your theme directory, and set your post’s category toFoo
, and that post will be rendered using thecategory-foo.php
template instead of the defaultpost.php
template.This mechanism for selecting templates has been present since WordPress 1.5, though full list of template types has grown significantly over the years.
The WordPress documentation for this can be found here.