Plugin Directory

Parentless Categories

Author: Scott Reilly

Like the_category(), list categories assigned to a post, but excluding assigned categories that have a child category also assigned to the post.

This plugin provides a template tag which acts a modified version of WordPress's built-in template tag, the_category(). the_category() lists all categories directly assigned to the specified post. parentless_categories() lists those categories, except for categories that are parents to other assigned categories.

For example, assume your category structure is hierarchical and looks like this:

Vegetables |-- Leafy | |-- Broccoli | |-- Bok Choy | |-- Celery |-- Fruiting | |-- Bell Pepper | |-- Cucumber | |-- Pumpkin |-- Podded | |-- Chickpea | |-- Lentil | |-- Soybean

If you directly assigned the categories "Fruiting", "Cucumber", and "Pumpkin" to a post, parentless_categories() would return a list that consists of: "Cucumber", and "Pumpkin". Notice that since "Fruiting" was a parent to a directly assigned category, it is not included in the list.

By default, categories are listed as an HTML list. The first argment to the template tag allows you to define a custom separator, e.g. to have a simple comma-separated list of categories: <?php parentless_categories(','); ?>.

As with categories listed via the_category(), categories that are listed are presented as links to the respective category's archive page.

Example usage (based on preceeding example):

<?php parentless_categories(); ?>

Displays something like:

<?php parentless_categories(','); ?></ul>

Displays something like: Cucumber, Pumpkin

Download

FYI

Compatibility beta

Your Setup

Log in to vote.

The Consensus

No data

Average Rating

5 stars
4 stars
3 stars
2 stars
1 star
(0 ratings)