OK, so there are many ways to solve this. You can use special template tags for some of these (for example the_archive_title
to show the title of current category, and so on).
But to achieve all of these, you’ll need to get get_queried_object
.
If you’re viewing category, this function will return current category object.
So after:
$current_cat = get_queried_object();
You can get its name using:
echo $current_cat->name;
And its id using:
echo $current_cat->term_id;
To get its parent:
if ( $current_car->parent ) {
$parent = get_category( $current_car->parent );
echo $parent->name;
echo $parent->term_id;
}
And to get all subcategories of $parent
:
$categories = get_categories( array('parent' => $parent->term_id) );
foreach($categories as $category) {
echo $category->name;
}
Related Posts:
- Edit the markup of categories list
- editing fonts of category links from the_category() funtion
- How to check category of of custom post type or not
- Set a them for all subset of category
- Can’t display posts by filtering categories using isotope.js
- Show posts from all categories
- altering theme – content generated by PAGES not PORTFOLIO
- get_terms vs. get_categories: does it matter?
- Woocommerce get category image full size
- Control term order on a per-post basis
- Fixing category count
- get_terms name__like list categories according to letter
- Elegant way to add parent categories?
- How can I select a primary category?
- How to get the url to tag & category base set by the user?
- How to create a widgetized sidebar for every category dynamically?
- Send an email when custom post type category is changed
- Are Categories, Tags and Custom Taxonomies any different in regards to SEO?
- Excluding posts from a category but only if they’re not in multiple categories
- Update term count using a callback function
- List Categories of the Parent Category of the Current Category
- Why adding Categories does not auto refresh in Backend while using my custom theme?
- Does WordPress Offer a Way to Find All of the Categories that Don’t Have Children?
- Add custom taxonomy terms to WordPress menu dynamically & append #slug to url
- Removed slug from CPT, now How/where do I hook the filter to the taxonomy term archive pages link?
- Getting the sub category
- Use get_term_children to get the sub category of a parent category for the current post
- Action hooks returning old category instead of new category
- Update wordpress post terms programatically
- Display empty taxonomy terms with get_terms()
- When to use ‘get_category_by_path’ vs. ‘get_term_by’ to get category object from `get_query_var( ‘category_name’ )`?
- How do I make the category template display full posts instead of partial posts?
- Single_cat_title() print the title before text
- How do I get a list of all categories that a given user has written blog posts for?
- How to add “Read More…” link in twentytwenty
- Limit number of terms that a custom taxonomy can save per custom post type
- Inserting Category programmatically
- How to call custom category field data in theme?
- How can i insert term in a specific language of Polylang?
- Why does the argument list_only do on Walker_Category_Checklist::start_el?
- WP didn’t redirect to canonical category URL
- Is There a Difference Between Taxonomies and Categories?
- Custom Walker for wp_list_categories
- Woo Framework: woo_cat_featured not populating
- Getting category URL with hyphens, not spaces
- get_terms function not returning anything
- Display custom taxonomy attached to the post on post single page
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Get a count of how many times a term or a category is used in posts
- Get Categories Where Taxonomy Equals ‘n’
- How to Link to Most Recent Custom Post of Same Term
- So my theme doesn’t have a category.php file
- Insert HTML content in WP Query at specific point
- set terms to category and subcategory
- Getting Category Children
- Showing HTML if Post is In Certain Taxonomy Term
- Theme modification for custom category menus
- How to add icon over specific thumb
- How to detect /category and /tag base pages?
- List categories of a post hierarchically?
- WooCommerce shared categories
- Add properties to term object
- Show the number of the post
- How to list posts from a sub-category that is listed in a parent category (more details below)?
- How can i add service category here? [duplicate]
- List taxonomy terms assigned to a post in hierarchical view
- Sort categories by custom field in WordPress admin
- How to get immediate children of a ‘term’ parent id through ‘get_terms’?
- Ordering terms whilst in loop
- Create category after theme setup and modify the default one
- Category page 404s on mobile but not desktop?
- Get WooCommerce product category list in functions.php
- List non-empty categories from a custom post type
- Media Library Categories
- Add subcategories posts to the counts column at the admin’s categories list
- Categories and Tags Conflict after Woocommerce Installation
- Get category of a taxonomy for a queries object in a loop
- get_terms sort order with child categories of varying depth
- Getting a sub category based on a category name
- How can I add HTML classes for current taxonomy/term hierarchy into my pages to simplify styles?
- Change single.php template based on parent category
- Getting Post Tags From Certain Categories
- Display List of Categories Within a Custom Taxonomy
- Choosing different templates for categories
- List Terms by category
- Lowest catagory link
- Removing categories, Comments etc from posts?
- How to add a new child category via an SQL statement?
- Why is my post categories not displaying?
- Problem importing categories and sub-categories
- Modify functions.php to add a term ‘uses-theme’ set to theme name on post save
- Use get variable when rewritten url in wordpress
- Category Archives: Show posts categorized in parent category only
- How can i hide the authors box from a specific set of categories and post types?
- Get all first images of posts in same category
- Issue on Listing Sub Product Categories In Woocommerce
- Taxonomy term RestApi data 10 rows limitions
- hide_empty property not working when using get_terms
- How to hide my categories pages’ names, and how as well to reduce the space beween my sidebar’s widgets?
- How to make /category/ URL load properly instead of 404 error?