Understanding the attachment heirarchy

Peanut Butter Bars can be attached to your WordPress site in several ways. This post details the hierarchy of how these attachments dictate which bar will be shown.

Attachment Heirarchy

  1. Post/Page individual setting
  2. Category setting
  3. Parent Category setting
  4. Default Bar

Individual Post/Page

If a post or page has a bar attached to it individually (see this help topic for more on this feature), this bar will always take precedence over any of the following rules.

Category Attachment

Bars can be attached to categories on the Attach bars to categories tab of the settings screen. Each category can only have one bar attached.

If a category has a bar attached, posts in that category as well as a category listing page will show this bar.

Subcategories inherit their parent’s bar

If a aub-category itself does not have a bar attached, but its parent category does, then the parent bar will be used. This will continue up the chain until either a bar is found or no bar is attached anywhere on the category hierarchy.

Default Bar

At the top of the “Attach bars to categories” tab on the settings page, you can assign a default bar for your site. This bar will show on any page on your site that is not otherwise configured.

This includes: archive listings, tag listings, search results, homepage (unless that set as a static page) and any error pages.

The “No bar” bar

On the “Attach bars to categories” there is an extra option in all of the dropdowns to choose a bar labeled “No bar”. Choosing “No bar” indicates that you do not want a bar attached to that category (or as a default).

Any individual posts in these categories with individual bars will still show their individual bars. This “No bar” will be inherited by subcategories that do not specifically have a category though.

Posts with multiple categories

Although you can only choose one bar per category, a post can have multiple categories. In this case, the first category will be used.

Which is the first category?

Peanut Butter Bar uses the WordPress standard function get_the_category and chooses the first one. If you have your link structure set to use category as a part of it, this should be the same category.

Not the category you want?

Posts can have individual bars attached. You can set a bar specifically on any post. (See this help topic.)

We are open to ideas as well. Drop us an email with your idea and situation.