Plugin Directory

Parentless Categories

Version: 1.1.3 Like the_category(), list categories assigned to a post, but excluding assigned categories that have a child category also assigned to

Download Version 1.1.3

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 argument 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 preceding example):

  • <?php parentless_categories(); ?>

Outputs something like:

<ul><li><a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a></li>
<li><a href="http://yourblog.com/category/fruiting/pumpkin">Pumpkin</a></li></ul>
  • <?php parentless_categories(','); ?></ul>

Outputs something like:

<a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a>, <a href="http://yourblog.com/category/fruiting/pumpkin">Pumpkin</a>

Links: Plugin Homepage | Plugin Directory Page | Author Homepage

Author: coffee2code

Requires: 2.5 or higher
Compatible up to: 3.3.1
Last Updated: 2011-7-15 Downloads: 1,044

Average Rating

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

Compatibility

+
=
Not enough data

0 people say it works.
0 people say it's broken.

Log in to vote.

0,1,0