Peer Categories
- Author:Scott Reilly
- Version:1.1.5
- Last update:2012-12-09
- Compatibility:WP 2.5 – 3.5.1
- Comments:go here
- Download:[ zip ]
- Description:
List the categories that are peer (i.e. share the same category parent) to all lowest-level assigned categories for the specified post.
-
Extended Description
List the categories that are peer (i.e. share the same category parent) to all lowest-level assigned categories for the specified 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.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 | |-- SoybeanIf 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:
<?php 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):
<?php peer_categories(); ?>
Outputs something like:
<ul><li><a href="http://yourblog.com/category/fruiting/bell-pepper">Bell Pepper</a></li> <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 peer_categories(','); ?></ul>
Outputs something like:
<a href="http://yourblog.com/category/fruiting/bell-pepper">Bell Pepper</a>, <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
Find out more at the plugin’s WordPress Plugin Repository page.
Installation
- Unzip
peer-categories.zipinside the/wp-content/plugins/directory for your site (or install via the built-in WordPress plugin installer) - Activate the plugin through the ‘Plugins’ admin menu in WordPress
- (optional) Add filters for ‘peer_categories’ to filter peer category listing
- Use the template tag
<?php peer_categories(); ?>somewhere inside “the loop”
- Unzip
-
Template Tags
The plugin provides three optional template tag for use in your theme templates.
Functions
-
<?php function peer_categories( $separator = '', $post_id = false ) ?>
Outputs the peer categories. -
<?php function get_peer_categories_list( $separator = '', $post_id = false ) ?>
Gets the list of peer categories. -
<?php function get_peer_categories( $post_id = false ) ?>
Returns the list of peer categories for the specified post.
Arguments
-
$separator
Optional argument. (string) String to use as the separator. -
$post_id
Optional argument. (int) Post ID. If ‘false’, then the current post is assumed. Default is ‘false’.
Examples
- (See Description section)
-
Frequently Asked Questions
Q. Why isn’t an assigned category for the post showing up in the ‘peer_categories()’ listing?
A. 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. Only peers to the lowest-level assigned categories are considered.
Release Log
1.1.5
- Note compatibility through WP 3.5+
- Update copyright date (2013)
1.1.4
- Re-license as GPLv2 or later (from X11)
- Add ‘License’ and ‘License URI’ header tags to readme.txt and plugin file
- Remove ending PHP close tag
- Note compatibility through WP 3.4+
1.1.3
- Note compatibility through WP 3.3+
- Add link to plugin directory page to readme.txt
- Update copyright date (2012)
1.1.2
- Note compatibility through WP 3.2+
- Minor documentation reformatting in readme.txt
- Fix plugin homepage and author links in description in readme.txt
1.1.1
- Note compatibility with WP 3.1+
- Update copyright date (2011)
1.1
- Wrap all functions in if (!function_exists()) check
- Remove docs from top of plugin file (all that and more are in readme.txt)
- Note compatibility with WP 2.9+, 3.0+
- Add PHPDoc documentation
- Minor tweaks to code formatting (spacing)
- Add package info to top of plugin file
- Add Changelog, Template Tags, and Upgrade Notice sections to readme.txt
- Update copyright date
- Remove trailing whitespace
1.0
- Initial release
Copyright & Disclaimer
Copyright © 2009-2012 by Scott Reilly (aka coffee2code)Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
