Home Plugins peer categories
Peer Categories logo

Peer Categories

by Scott Reilly on WordPress.org

List the categories that are peer (i.e. share the same category parent) to all lowest-level assigned categories for the specified post.

(0)

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. c2c_peer_categories() lists those categories PLUS any categories that are peer to those categories and MINUS categories that are parents to other assigned categories. Peer categories are categories that all share the same category parent.

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” and “Pumpkin” to a post, peer_categories() would return a list that consists of: “Bell Pepper”, “Cucumber”, and “Pumpkin”. Notice that since “Fruiting” was a parent to a directly assigned category, it and its peers are not included in the list. If only “Fruiting” were selected as a category, then “Leafy”, “Fruiting”, and “Podded” would have been listed.

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 peer 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):

Outputs something like:


Outputs something like:

Bell Pepper, Cucumber, Pumpkin

Links: Plugin Homepage | Plugin Directory Page | GitHub | Author Homepage

Developer Documentation

Developer documentation can be found in DEVELOPER-DOCS.md. That documentation covers the template tags and hooks provided by the plugin.

As an overview, these are the template tags provided by the plugin:

  • c2c_peer_categories() : Outputs the peer categories.
  • c2c_get_peer_categories_list() : Returns the list of peer categories.
  • c2c_get_peer_categories() : Returns the list of peer categories for the specified post.

These are the hooks provided by the plugin:

  • c2c_peer_categories (action), c2c_get_peer_categories_list, c2c_get_peer_categories (filters) :
    Allows for an alternative approach to safely invoke each of the identically named functions in such a way that if the plugin were deactivated or deleted, then your calls to the functions won’t cause errors on your site.
  • c2c_peer_categories_list (filter) :
    Customizes the return value of the c2c_peer_categories_list() function.
  • c2c_get_peer_categories_omit_ancestors (filter) :
    Customizes 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.
Active installations10+
Weekly downloads
15+7.14%
Version2.3.1
Last updated4/21/2025
WordPress version4.6
Tested up to6.8.1
Tags
categorycoffee2coderelated postssiblingthe_category