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 function not returning anything
- How to do some action weekly?
- Display custom taxonomy attached to the post on post single page
- wp_dropdown_categories not showing option as selected
- Ive got a term (get_term_by) but now I want to filter it by a category it is in?
- Question on using custom structures for categories
- Get a count of how many times a term or a category is used in posts
- Get Categories Where Taxonomy Equals ‘n’
- Display sibling categories on category page
- Getting the category title / description returns first matching post?
- Count tags for a specific category
- How to Link to Most Recent Custom Post of Same Term
- So my theme doesn’t have a category.php file
- Allow user to select categories that will display in post loop
- Insert HTML content in WP Query at specific point
- How do I retrieve the category ID (ugly permalinks) in my sub-navigation menu?
- set terms to category and subcategory
- Category page returns 404 error
- Getting Category Children
- Theme for subcategories
- More efficient way to list posts by category [duplicate]
- Showing HTML if Post is In Certain Taxonomy Term
- Theme modification for custom category menus
- Show post categories
- Exclude categories by ID
- Add description to categories menu in admin
- filter a loop base on specific category
- Problem with multiple loops in wordpress theme
- Using in ‘category_name’ in ‘$query->set();’?
- How to store category and tags separatly on wordpress?
- How to add icon over specific thumb
- How to differentiate the homepage structure from the category page structure in WordPress template?
- Post to inherit custom category background image from parent
- wp_delete_term or wp_delete_category?
- How to detect /category and /tag base pages?
- Update custom category fields front-end
- Combining these queries? (Same taxonomy term + same category as post)
- List categories of a post hierarchically?
- WooCommerce shared categories
- WP-CLI Add category as menu item main-menu
- Add properties to term object
- get_object_term_cache duplicate terms after update to wordpress 6
- 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]
- How do I edit the terms output args or array data?
- List taxonomy terms assigned to a post in hierarchical view
- How do I remove “Uncategorized” from my theme on my posts page?
- Sort categories by custom field in WordPress admin
- Products category search not working
- How to get immediate children of a ‘term’ parent id through ‘get_terms’?
- Ordering terms whilst in loop
- In if…else condition, the else statement shows even if if statement is correct
- Replace deprecated get_category_children code with get_terms
- Create category after theme setup and modify the default one
- How to remove parent category from child category url using wordpress rewrite rule?
- Category page 404s on mobile but not desktop?
- Regarding Tags And Categories
- Get WooCommerce product category list in functions.php
- Restrict retrieved terms by category?
- List non-empty categories from a custom post type
- How to modify custom category field from front end?
- How to show some of category in wordpress
- outputting taxonomy hierarchy
- Bulk Change WordPress category Slug
- Media Library Categories
- Add subcategories posts to the counts column at the admin’s categories list
- Style a category page the same way as the homepage?
- show only terms from parent category
- 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
- Jetpack Mobile Theme: when on smartphone on categories the theme suddenly changes to jetpack mobile theme even though it’s deactivated
- Choosing different templates for categories
- List Terms by category
- If it is a top level category show children otherwise show sibling categories
- Lowest catagory link
- Removing categories, Comments etc from posts?
- get_adjacent_post_link excluded_terms ignored
- Include category name in page template
- How to add a new child category via an SQL statement?
- How to get multiple loop in category.php, my scripts becomes madness
- Category base 404 – fix
- Why is my post categories not displaying?
- Category page with gallery for each post
- exclude parents from the_terms
- Custom built theme won’t filter categories
- Problem importing categories and sub-categories