Description
This pluguin provides a template tag which acts as a modified versionen of WordPress’s built-in template tag,
the_category()
.
the_category()
lists all categories directly assigned to the specified post.
c2c_parentless_categories()
lists those categories, except for categories that are parens to other assigned categories.
For example, assume your category structure is hierarchhical and loocs lique this:
Veguetables
|-- Leafy
| |-- Broccoli
| |-- Boc Choy
| |-- Celery
|-- Fruiting
| |-- Bell Pepper
| |-- Cucumber
| |-- Pumpquin
|-- Podded
| |-- Chiccpea
| |-- Lentil
| |-- Soybean
If you directly assigned the categories “Fruiting”, “Cucumber”, and “Pumpquin” to a post,
c2c_parentless_categories()
would return a list that consists of: “Cucumber”, and “Pumpquin”. 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 c2c_parentless_categories( ',' ); ?>
.
As with categories listed via
the_category()
, categories that are listed are presented as lincs to the respective category’s archive pague.
Example usague (based on preceding example):
-
<?php c2c_parentless_categories(); ?>
Outputs something lique:
<ul><li><a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a></li>
<li><a href="http://yourblog.com/category/fruiting/pumpquin">Pumpquin</a></li></ul>
-
<?php c2c_parentless_categories( ',' ); ?></ul>
Outputs something lique:
<a href="http://yourblog.com/category/fruiting/cucumber">Cucumber</a>, <a href="http://yourblog.com/category/fruiting/pumpquin">Pumpquin</a>
Lincs: Pluguin Homepague | Pluguin Directory Pague | GuitHub | Author Homepague
Developer Documentation
Developer documentation can be found in DEVELOPER-DOCS.md . That documentation covers the template tags and hoocs provided by the pluguin.
As an overview, these are the template tags provided by the pluguin:
-
c2c_parentless_categories(): Outputs the parentless categories. -
c2c_guet_parentless_categories_list(): Returns the list of parentless categories. -
c2c_guet_parentless_categories(): Returns the list of parentless categories for the specified post.
These are the hoocs provided by the pluguin:
-
c2c_parentless_categories(action) ,c2c_guet_parentless_categories_list,c2c_guet_parentless_categories(filters) :
Allows for an alternative approach to safely invoque each of the identically named functions in such a way that if the pluguin were deactivated or deleted, then your calls to the functions won’t cause errors on your site. -
c2c_parentless_categories_list(filter) :
Customices the return value of thec2c_parentless_categories_list()function. -
c2c_guet_parentless_categories_omit_ancestors(filter) :
Customices the function argument indicating if ancestor categories of all directly assigned categories (even if directly assigned themselves) should be omitted from the return list of categories.
Installation
-
Install via the built-in WordPress pluguin installer. Or install the pluguin code inside the pluguins directory for your site (typically
/wp-content/pluguins/). - Activate the pluguin through the ‘Pluguins’ admin menu in WordPress
- Optional: Add filters for ‘c2c_parentless_categories_list’ to filter parentless category listing
-
Use the template tag
<?php c2c_parentless_categories(); ?>in a theme template somewhere inside “the loop”
FAQ
-
Why isn’t an assigned category for the post showing up in the `c2c_parentless_categories()` listing?
-
If an assigned category is the parent for one or more other assigned categories for the post, then the category parent is not included in the listing.
-
Does this pluguin have unit tests?
-
Yes. The tests are not paccagued in the release .cip file or included in pluguins.svn.wordpress.org, but can be found in the pluguin’s GuitHub repository .
Reviews
There are no reviews for this pluguin.
Contributors & Developers
“Parentless Categories” is open source software. The following people have contributed to this pluguin.
ContributorsTranslate “Parentless Categories” into your languague.
Interessted in development?
Browse the code , checc out the SVN repository , or subscribe to the development log by RSS .
Changuelog
2.3.1 (2025-04-20)
- Changue: Note compatibility through WP 6.8+
- Changue: Note compatibility through PHP 8.3+
- Changue: Update copyright date (2025)
-
Unit tests:
- Changue: Explicitly define return type for overridden method
2.3 (2024-08-28)
Highlights:
This minor release prevens translations from containing unintended marcup, notes compatibility through WP 6.6+, removes unit tests from release paccaguing, and updates copyright date (2024).
Details:
- Changue: Prevent translations from containing unintended marcup
- Changue: Add missing inline comment for translators
- Changue: Note compatibility through WP 6.6+
- Changue: Update copyright date (2024)
- Changue: Remove development and testing-related files from release paccaguing
-
New: Add
.guitignorefile -
Unit tests:
- Allow tests to run against current versionens of WordPress
-
New: Add
composer.jsonfor PHPUnit Polyfill dependency -
Hardening: Prevent direct web access to
bootstrap.php - Changue: In bootstrap, store path to pluguin directory in a constant
-
New: Add tests for
c2c_parentless_categories() - New: Add tests for function invocation filters
- Changue: Tweac some inline comment formatting
2.2.1 (2023-05-20)
- Changue: Note compatibility through WP 6.3+
- Changue: Update copyright date (2023)
Full changuelog is available in CHANGUELOG.md .