This is a general solution for all taxonomies. To be used inside the loop (else replace get_the_ID()
with post ID ):
$taxonomy = 'category';
$terms = get_the_terms( get_the_ID(), $taxonomy );
if( $terms ){
$term_slugs = array_map('esc_attr',wp_list_pluck( $terms, 'slug'));
$class = implode(' ', $term_slugs);
}else{
$class="no-term";
}
Related Posts:
- How can I custom order the results from wp_list_categories?
- wp_list_categories: get latest featured_image of category
- Exclude category by slug for for each loop
- Display page of custom posts?
- Showing current subcategory
- Why is my loop not dynamically grabbing the correct Category and displaying all categorized posts?
- Publish Categories for a particular Author on a given Post
- Loop Problem: Displays same set of post for all categories
- Category ID returns as ‘0’?
- Three Column Loop
- Exclude category from get_the_category
- loop inside a loop : search for posts in the same category
- Show all child categories associated to post ID within loop
- Secondary loop cuts off at 10 posts?
- My custom query not detecting the correct category
- Show last post from multiple categories using wp_list_categories
- loop mix my child-category and parent-category
- Retrieve each widget separately from a sidebar
- how to upload image using wp_handle_upload
- Avoiding using a loop to access a single post
- Adding ‘current_post_item’ class to current post in the loop
- WordPress Alphabetical Glossary close div in loop
- Where should I use post_class()?
- Listing all posts from current category on page
- Landing Page – Redirect Loop?
- How to make multiple Column in archive Page?
- Sort Popular Posts by Views for the Last Week
- Filtering posts by multiple taxonomies
- Query Custom Post by Category
- Is it possible to display previous post revision?
- Listing Parent, Child and GrandChild Categories and then the PostTitles on Page Template !
- Help with Changing loop.php?
- Adding shortcode closing tag after a loop
- Get Pagination (WP-PageNavi) not to work
- Filtering The Loop For Single Page and Blog Page
- the_content() seems to block my ACF-code
- Removing the_content() from the page
- Change front-page layout after x amount of posts ( while in the same loop)
- How can i use the same template file with a widget and category loop?
- Filter the loop by categories using checkbox form
- Duplicated posts on category page
- WordPress loop: exclude if it is the latest post
- Custom post type, organized by categories
- angularjs not displaying all posts
- query_posts() vs get_posts() multiple loops [duplicate]
- Page-loop is looping content from custom loops on the same site. How to avoid that?
- Order by category titles
- How do I make a variable available inside partials?
- WordPress: Loop Help
- is_active-sidebar loop
- why does wordpress ignore the post args?
- Unable to change the “Read more” text inside the_excerpt
- Display Post Author Link above the loop
- Enabling users to control custom loop’s query
- Recent posts per category loop?
- Conditional: IF current user has NOT commented on current post (not including post author)
- Loop counter style
- Can I add generic numbering HTML classes to items as a loop runs?
- Change post order by meta key, per post basis
- Category archive is displaying all posts rather than the specific category
- Custom Post Type on Homepage – Studiopress Genesis Framework
- issue with if/elseif in_array inside foreach loop display only one post
- display post format text in loop
- How to display the parent category if only the child category has been chosen
- Yoast taking over my WordPress title tag [closed]
- How do i find and restore a sidebar that i accidentally deleted? [closed]
- Posts not showing
- Remove any product that is featured from regular display loop [WooCommerce]
- Use BuddyPress data in loop (mkdir)
- Wrap every four posts within a div [duplicate]
- Get most recent post for every term in a given taxonomy type
- Can’t grab author info outside of the loop
- Is file_exists() compatible with timthumb.php? [closed]
- get post images to link to external sources
- Exclude parent categories from the_category() within the loop
- Set depth of pages to fetch
- Trying to get all links in my posts
- Creating a User-Adjustable chart in WordPress
- Return to the beginning of the results of a for loop
- Archive: Lists itself
- Reorder posts in a loop: have the posts by one particular author below the others
- How to execute a user loop with shortcode
- how to get author comment inside the loop?
- How to create loop in custom page, and get id from url into this loop?
- How to fix pagination for custom loops?
- Loop Posts Outside of WordPress Installation
- Custom Post Type + Category archive
- How to exclude a specific categogy from a custom page template
- Display single post inside accordion based on form submission results
- One page loop issue with posts
- Building theme so user can change header image [closed]
- display only parent replies count in index.php
- using the loop on a page
- How do i add custom post types to this query?
- While loop inside another while loop
- Do not show all post from all categories, just show posts from category in current loop
- get_page() unlike Loop returns the post content without html tags. How can I fix this?
- Fix html inside a for loop [closed]
- Display all posts in a page code for template
- Use Base-URL with Query-Loop