use a conditional statement, for example:
$sub_cats = get_categories('parent=".get_query_var("cat'));
if( $sub_cats ) :
//show list of child categories, for instance with wp_list_categories()
echo '<ul>;
wp_list_categories('title_li=&child_of=".get_query_var("cat'));
echo '</ul>';
//or possibly using $sub_cats and a foreach loop//
echo '<ul>';
foreach( $sub_cats as $sub_cat ) {
echo '<li><a href="'.get_category_link($sub_cat->term_id).'">'.$sub_cat->name.'</a></li>';
}
echo '</ul>';
else:
//the 'normal' LOOP of category.php//
endif;
http://codex.wordpress.org/Function_Reference/get_categories
http://codex.wordpress.org/Template_Tags/wp_list_categories
edit: list code for sub categories added
Related Posts:
- Decreasing the Memory Consumption of a WordPress Site?
- Gutenberg editor add a custom category as wrapper for custom blocks
- How to get category and archive title?
- Get rid of WordPress category, tag and author archives?
- Category archive by year with permalink support /category/YYYY
- get_categories for custom post type with a specific custom taxonomy attached
- How To Modify The Loop in archives.php To Have 11 Posts Per Page and CSS Styling
- How can I hide a category from Contributors in the edit/add new post screen?
- WordPress Multiple Category Search
- How to remove categories filter from wordpress admin?
- 404 Error On Category and Tags Pages
- Force WordPress to Show Pages Instead of Category
- What’s the URL for a category archive?
- How can I get posts in a subcategory to display on it’s parent categories archive page?
- Multiple Domain Names – One WP Install (non-Multisite) – Default Each Domain name to Category Archive
- How can I select a primary category?
- how to use a different domain/subdomain for authors/catagories on single site?
- Deleting default category in wordpress
- Sort posts by tags in category pages
- Delete a specific category when deleting a user
- How to get the category of the post and link it to the archive (of the category)
- How to hide a specific category posts in my monthly archive?
- How to list child categories in custom category template?
- Optimal way to redirect home page to category archive?
- Display posts links from a category group by year
- Trash bin for categories
- Display list of Sub-Categories and the posts they contain, within one main Category
- How to set up sub-categories for author pages?
- View category in the preview of Theme Customizer
- Sort category page with custom field
- How to create tabled index of posts in a certain category
- One WordPress Install, Two Categories. Each Category Gets a Domain
- Block multiple categories from Blog
- How would you create a “weekly” archive?
- Sticky Posts Not Sticking to Top of Category Archive
- Root level category, tag, author and archive pages to work
- How to have a static category/author page?
- Create single.php for specific category by category id
- Show posts of one category only with Custom Taxonomy on single.php
- Save metabox checkboxes values to custom content type
- Select category in custom query
- Category Specific Archive
- How to have Multiple Archives Widgets, one archive widget per category (in a different page)?
- Are Custom Taxonomy Templates Possible?
- “Sticky” posts for each category (archive.php)
- Remove “Parent” Selection When Adding/Editing Categories?
- I want exclude the particular category in sidebar
- Order Taxonomy Term by date created
- How to filter archives both by category and tag?
- Remove Archive Headline and Archive Intro Text fields on category and tag archive pages in WordPress Admin with Genesis framework
- Display only posts from referred category on date archive page
- Using widget logic I want to show only a widget on the archive page if there are no posts
- What type of page should i use? static page or category page? and what’s the difference? [closed]
- Apply custom category template to subcategories
- Hide post meta data on a specific category
- Creating archive pages for children categories
- Format Brand value in Category view [closed]
- Add custom taxonomy under the category title
- How to show in search results posts with a particular tag in a particular category?
- Display “add to cart” button on every listing in product category page?
- What is the advantage of using header-catname.php over is_category(‘catname’);?
- Remove ‘rel’ attributes from the_category() output
- Multiple menu items highlighted
- WordPress categories being called “archives” in google links. How to remove?
- in_category() works in single.php but not in page.php?
- Use a wordpress page to display a certain category
- conditional for sub category on archive page
- Sorting posts by season
- How to view WordPress’ default category IDs?
- weekly archive for custom category
- WP_Query() returns null when results exist!
- Multiple Category Search
- How do I add a function on a specific post category?
- WordPress subcategories return 404 in custom template
- How to customize category template?
- How to remove category titles?
- Show archives by year from just one category
- Category-slug.php not being used
- How would I go about adding custom header images per category?
- Archives for each category on WP Multisite
- Category index featured image
- Archive.php filtered by pre-determined category
- How do I call posts with a certain tag?
- Automatically exclude categories from metabox based on title
- Display posts separated by Category in Author’s page
- Category being displayed without base parmalink
- How to change category and year archive permalinks/rewrite rules?
- How can I define a custom archive for childs of a specific category?
- Get parrent category name
- Restoring default article pagination on archives – Removing custom limits
- Category archive rewrite rule to include category/subcategory?
- How to categorize posts under Category 1 and Category 2 which are separate lists of categories, and display them as separate lists in widgets
- add_rewrite_endpoint returns 404 on archives
- Multiple category archive page
- How to organize custom categories for filtering and selecting
- Custom archive.php: retrieve right post categories?
- wp_dropdown_categories() scripts working erratically on sidebar
- Yearly Archive for Categories with dropdown
- Filtering *out* a taxonomy from the admin post list
- How to rewrite the post URL according to the category?