WordPress.org

Ready to get started?Download WordPress

Plugin Directory

Peer Categories

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

Template Tags

The plugin provides three optional template tag for use in your theme templates.

Functions

  • <?php function c2c_peer_categories( $separator = '', $post_id = false ) ?> Outputs the peer categories.

  • <?php function c2c_get_peer_categories_list( $separator = '', $post_id = false ) ?> Gets the list of peer categories.

  • <?php function c2c_get_peer_categories( $post_id = false, $omit_ancestors = true ) ?> 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'.

  • $omit_ancestors Optional argument. (bool) Should any ancestor categories be omitted from being listed? If false, then only categories that are directly assigned to another directly assigned category are omitted. Default is 'true'.

Examples

  • (See Description section)

Filters

The plugin is further customizable via five hooks.

c2c_peer_categories (action), c2c_get_peer_categories_list, c2c_get_peer_categories (filters)

These actions and filters allow you to use an alternative approach to safely invoke each of the identically named function 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.

Arguments:

  • (see respective functions)

Example:

Instead of:

<?php c2c_peer_categories( ',' ); ?>

or

<?php $peers = c2c_get_peer_categories( $post_id ); ?>

Do (respectively):

<?php do_action( 'c2c_peer_categories', ',' ); ?>

or

<?php $peers = apply_filters( 'c2c_get_peer_categories', $post_id ); ?>

c2c_peer_categories_list (filter)

The 'c2c_peer_categories_list' filter allows you to customize or override the final result of the function.

Arguments:

  • string $thelist : the generated list of categories with complete HTML markup, or __( 'Uncategorized' ) if the post didn't have any categories
  • string $separator : the separator specified by the user, or '' if not specified
  • int|false $post_id : the ID of the post, or false to indicate the current post Example:
// For comma-separated listings, append a special string
add_filter( 'c2c_peer_categories_list', 'customize_c2c_peer_categories_list' );
function c2c_peer_categories_list( $thelist, $separator ) {
    // If not categorized, do nothing
    if ( __( 'Uncategorized' ) == $thelist ) {
        return $thelist;
    }

    // Add a message after a comma separated listing.
    if ( ',' == $separator ) {
        $thelist .= " (* not all assigned categories are being listed)";
    }

    return $thelist;
}

c2c_get_peer_categories_omit_ancestors (filter)

The 'c2c_get_peer_categories_omit_ancestors' filter allows you to customize or override 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. By default, this argument is true.

Arguments:

  • bool $omit_ancestors : the $omit_categories argument sent to the function, otherwise implicitly assumed to be the default

Example:

// Don't omit ancestors unless they are the immediate parent of an assigned category
add_filter( 'c2c_get_peer_categories_omit_ancestors', '__return_false' );

Requires: 3.6 or higher
Compatible up to: 3.8.3
Last Updated: 2014-1-10
Downloads: 2,202

Ratings

4 stars
4 out of 5 stars

Support

Got something to say? Need help?

Compatibility

+
=
Not enough data

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