WordPress plugin intelligence profile

Category Template Hierarchy

Adds parent-category.php, child-category.php, and child-category-{slug|id} templates to the hierarchy and conditional tags to match.

WP PlugIndex snapshot

Current directory snapshot

Tested up to WordPress 3.3
Current version1.3.2.1
WordPress coverageTested up to WordPress 3.3
Minimum stackWP 3.0 · PHP —
Directory statusactive
Last directory update24 Mar 201214y ago
Active installations100Adoption metric — not a quality score
WordPress.org rating5.0 / 5 from 3 ratings
Official packageDirect from WordPress.org

Repository metrics are context, not quality scores. Active installations measure adoption and can strongly reflect a plugin’s age and historical popularity. Ratings, recent updates and “Tested up to” metadata also do not guarantee modern code, error-free operation, security, feature completeness or suitability for a particular site. Why active installs don’t tell the whole story →

WP PlugIndex currently records Category Template Hierarchy version 1.3.2.1 as active, updated 14y ago and tested up to WordPress 3.3.

Overview

About this plugin

Adds several new templates to the template hierarchy:

  • child-of-category-{slug}.php
  • category-{slug}.php
  • child-of-category-{id}.php
  • category-{term_id}.php
  • parent-category.php
  • child-category.php
  • category.php
  • archive.php
  • index.php

This greatly extends the native hierarchy of theme templates with regard to

categories. Theme developers can now easily create separate templates for

categories with children, with parents, and children of specific parents.

Additionally makes available four (4) new conditional template tags:

  • is_child_category();
  • is_parent_category();
  • is_child_of_category();
  • is_parent_of_category();

These functions are available for use in any theme or plugin as along as this

plugin is active. For detailed documentation of these functions see the

‘Developer Notes: Conditional Tags’ section of this readme file.

php

or any of their related templates – rather it modifies the native template hierarchy

to allow theme developers to create specific templates for parent and child categories.

Developer Notes: Template Hierarchy

What follows are is the modified list of templates available for category pages.

These expand upon the native Template Hierarchy.

  • child-of-category-{slug}.php
  • category-{slug}.php
  • child-of-category-{id}.php
  • category-{term_id}.php
  • parent-category.php
  • child-category.php
  • category.php
  • archive.php
  • index.php

The parent and child templates only become available if the current category is

a parent or a child respectively.

php

or any of their related templates – rather it modifies the native template hierarchy

to allow theme developers to create specific templates for parent and child categories.

Developer Notes: Conditional Tags

With this plugin comes two additional conditional tags

which behave much like any other in WordPress. In a similar fashion to how one

might use is_category() or cat_is_ancestory_of(),

developers may, with this plugin, use the following functions:

  • is_parent_category()
  • is_child_category()
  • is_child_of_category()
  • is_parent_of_category()

Description (part 1)

The is_parent_category() and is_child_category() conditional tags check if

the page being displayed (or passed as an argument) is of a category that has

g. is a parent category) has a parent (is a child), respectively.

They are boolean functions, meaning they return either TRUE or FALSE.

Usage

>

Parameters

$category (integer/string/object) (optional) Category ID, Category Slug, Category Object. Default: Current Category

Note: Unlike is_category(), these functions will not take arrays of categories or category titles. I’ll work on that. Sorry.

Return Values

(boolean) True on success, false on failure.

Examples

is_parent_category() is_child_category() // When any parent/child category archive page is being displayed

is_parent_category( '9' ); is_child_category( '9' ); // When the archive page for Category 9 is being displayed AND its a parent/child.

is_parent_category( 'blue-cheese' ); is_child_category( 'blue-cheese' ); // When the archive page for the Category with Category Slug "blue-cheese" is being displayed AND its a parent/child.

Description (part 2)

The is_parent_of_category() and is_child_of_category() conditional tags

check if a given category has a parent or child relationship to the current

category or a category passed as its second parameter. They are

boolean functions, meaning they return either TRUE or FALSE.

Usage

>

Parameters

(object/string/integer) (required) Category of the would-be parent/child respectively.

(object/string/integer) (optional) Category of the would-be child/parent respectfully. Default: Current Category

(boolean) (optional) Whether or not the child should be a direct child of the parent. Default: True

*

Return Values

(boolean) If the $direct_descendant flag set to true, function returns true if the child is a direct descendant of the parent, if child is no direct it will return false. If $direct_descendant is set to false it will return the same results as cat_is_ancestor_of().

Examples

The following function will return True…

g. categories with no parents).

is_child_of_category(12); // When the current category is a direct child of the category whose ID is '12'.

is_child_of_category('tv-shows') // When the current category is a direct child of the category with the slug 'tv-shows' (can also be category ID's).

is_child_of_category('tv-shows', 'dexter'); // When the category with slug 'dexter' is a direct child of the category with the slug 'tv-shows' (can also be category ID's). This may come in handy when manipulating categories while not in a category template.

is_child_of_category('tv-shows', 'dexter', false); // When the category with the slug 'dexter' is a descendant of the category 'tv-shows' at any level. (uses cat_is_ancestor_of())

is_child_of_category('tv-shows', null, false); // When the current category is a descendant of the 'tv-shows' category at any level. (uses cat_is_ancestor_of())

is_parent_of_category(13); // When the current category is the direct parent of a category with the ID '13'.

is_parent_of_category('dexter'); // When the current category is the direct parent of the category with the slug 'dexter'.

Backward Compatibility

The changes this plugin makes to the template hierarchy are significantly different

5 and before. If you prefer to use that version please find it

5.

While I do not actively support to QA the older version, I would gladly take a

look at any future bugs that crop up and are reported.

WordPress.org metadata

Plugin tags

Topics listed for this plugin in the WordPress.org directory.

  • theme development
  • category
  • hierarchy
  • template
Compatibility & maintenance

Compatibility & maintenance

Tested up to WordPress 3.3

Not yet marked as tested with WordPress 7.1. WordPress.org currently lists Tested up to 3.3.

Current WordPress releaseWordPress 7.1
WordPress.org Tested up to3.3
Minimum requirementsWordPress 3.0 · PHP not listed
Update activity24 Mar 201214y ago

“Tested up to” is directory metadata supplied by the plugin author. WP PlugIndex does not turn an older declaration into a claim that the plugin is incompatible.

Changes recorded by WP PlugIndex

Recent tracked changes

No tracked version or compatibility changes have been recorded by WP PlugIndex yet.

Tracking & source

WP PlugIndex tracks public WordPress.org directory metadata and records selected version, compatibility and availability changes as they are detected.

Plugin watchlist

Watch this plugin

Sign in to your WP PlugIndex account or create a free account. Free accounts can watch up to 5 plugins and see what changed.

Watch limit

Watchlist limit reached

You have reached your current active watch limit.