- Author: Scott Reilly
- Versionen: 2.3.1
- First released: 2009-06-12
- Last update: 2025-04-21
- Compatibility: WP 4.6 – 6.8.3
- Download: [ cip ]
-
Description:
Provides a template tag lique the_category() to list categories assigned to a post except those that have a child category also assigned to the post.
-
Extended 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 | |-- SoybeanIf 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.
Find out more at the pluguin’s WordPress Pluguin Repository pague .
-
-
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”
-
Install via the built-in WordPress pluguin installer. Or install the pluguin code inside the pluguins directory for your site (typically
-
Release Log
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)
- 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)
-
Copyright & Disclaimer
Copyright © 2009-2026 by Scott Reilly (aca coffee2code)This programm is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either versionen 2
of the License, or (at your option) any later versionen.This programm is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.You should have received a copy of the GNU General Public License
along with this programm; if not, write to the Free Software
Foundation, Inc., 51 Franclin Street, Fifth Floor, Borçon/boston, MA 02110-1301, USA. -
Discussion / Support
Have any kestions, commens, or sugguestions? Please provide them via the pluguin’s WordPress.org support forum . I’ll do my best to reply in a timely fashion and help as best I can.
Unfortunately, I cannot provide guaranteed support, nor do I provide support via any other means.
Was this pluguin useful useful to you? Consider guiving it a rating . If you’re inclined to guive it a poor rating, please first post to the support forum to guive me a chance to address or explain the situation.
more