you probably need to get the parent category of each of the post’s categories first.
<?php
$parent_cat = array();
$post_cats = get_the_category($post->ID);
foreach( $post_cats as $post_cat ) {
if( $post_cat->parent ) $parent_cat[] = get_category( $post_cat->parent )->slug;
}
?>
<article class="post <?php
if ( in_array( 'dream-it', $parent_cat ) ) { echo ' dreamit'; }
if ( in_array( 'build-it', $parent_cat ) ) { echo ' buildit'; }
if ( in_array( 'get-the-hell-out', $parent_cat ) ) { echo ' getout'; } ?> ">
Related Posts:
- Allow users to create their own feed from selected categories?
- Completely disable categories
- get_field not displaying my custom field value
- Show div only if post is in specific category
- wp_list_categories exclude not working
- Assigning a category to a user role
- Is it possible to disable certain user roles from creating tags?
- what is the action hook code to supporting product category condition in single product page of woocommerce?
- Prevent function from triggering again when post in specific category gets another category?
- Posts from multiblt categories but featured image only in the first one, the rest to have the post title only
- Conditional Tag for sub cagtegories?
- Display only posts from referred category on date archive page
- Sort post’s categories by ID
- Add a wordpress blog to my website having users
- Allow contributors to add categories, but not delete
- in_category() not working in WordPress 4.9.7
- PHP Fatal error: Cannot use object of type WP_REST_Response as array in wp-includes/rest-api/endpoints/class-wp-rest-posts-controller.php
- WordPress categories being called “archives” in google links. How to remove?
- Show Featured products in product category pages
- Show recent posts from one category on a non-WP site
- Omit specific product categories from WooCommerce shortcode
- How to remove category titles?
- Inserting Category programmatically
- Category-slug.php not being used
- How to get grandparent of a given category
- Additional form options based on category selected not working
- Pagination for category slug returns 404 when page >= 2
- Display category-specific comments in sidebar
- Why does the argument list_only do on Walker_Category_Checklist::start_el?
- I want to display posts common in 3 categories [closed]
- Paging not working in category.php
- Display list of categories filtered by date?
- Drop posts from categories in MySql
- Redirect single article permalink to paginated category page
- Exclude category by slug in pre_get_posts?
- add slug beside name in Admin Category Checklists
- How to show 5 posts from specific category on related page?
- List only categories i specify
- Author Page – List of categories plus number of posts in that category
- Exclude category from related post
- Post belonging to many categories
- how do I use the walker class to display categories in their correct heirarchy?
- How can you access category information from a theme?
- Filter WooCommerce archive pages by an additional category
- WP 4.7 in_category change?
- display category list year wise in wordpress
- Display subcategories in dropdown
- Illegal string offset ‘taxonomy’ in
- How Do I Delete WordPress Posts Older Than 400 Days, From A WordPress Category
- Category Page Template – Can’t get category ID
- Are term_taxonomy_id and term_id the same? [duplicate]
- Display all sub category but one
- Filter Category Loop Dynamically
- SQL query to get posts from multiple categories but not in a category
- Can each user have only access to a private area (his own categories and posts)?
- Shortcode to display all the post from a category in a page
- WP Category Meta plugin fix? [closed]
- WP SQL Categories Export and Import
- How to display WooCommerce category image in my category page banner as a background?
- Why are my newly added categories not showing up when creating a post?
- WordPress Default Category and Custom Taxonomy Selected Attribute not Working After Searched in wp_dropdown_categories Array
- Order wp_dropdown_categories by ASC or DESC
- Add filter for specific category only
- How to exclude a category returned by get_categories from function.php?
- add woocommerce archive description if exist
- Can’t display posts by filtering categories using isotope.js
- Get a list of categories, separated by / to display inside the for custom metatags
- Is there a reason to put a product in both the Child and Parent Categories?
- Get_term_meta() always returns false
- Displaying only selected categories
- No results found for second level category
- get_the_category vs wp_get_post_categories
- How to get get_categories()’s ‘hide_empty’ argument to work with global year var in the archive template?
- Getting a sub category based on a category name
- How to display only sticky posts on category pages?
- Conditional statement: if is_category, append at the end of page
- I have many different products on my website how can I get them to display under specific categories?
- Help with SQL query, how to add taxonomie terms with value stored in options?
- /blog/ permalink prefix causes category pages to 404
- How to create an array with category ids order by the one that has the most recent post
- Categories in media library
- WordPress Shop and restricting products and categories for some users/groups
- Pass list of categories to JS
- WP url to get rss with full text of post
- Display Referring Category on single post?
- Conditional statements based on custom meta value in category archives
- Placement of categories
- Paginating a list of all posts collected by category titles
- Display deepest post category, when post have multiple categories
- Paginate WordPress Category Pages
- Get a list of post titles and links from yootheme master theme
- How to structure Multisite sites into categories?
- how wordpress generates permalinks as /%category%/%post%/
- How to make that all posts with a category belong also to another
- Featured image for links and categories
- How to change category id on get_posts array
- IF have_posts contains posts from a certain category
- wp_list_categories() not listing categories
- List the category tree of all the product_cat categories
- Is there a function to modify existing previous/next post link without modifying theme files?