Title: Comma between subcategory list
Last modified: August 20, 2016

---

# Comma between subcategory list

 *  Resolved [Rose](https://wordpress.org/support/users/eos-rose/)
 * (@eos-rose)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/comma-between-subcategory-list/)
 * In my single.php file I am trying to list all the child categories under a specific
   parent category. I’m using the following code:
 *     ```
       if(!function_exists('subcat')){
       	function subcat(){
       		global $post;
       foreach((get_the_category()) as $category)
       {
           if ($category->category_parent == "177")
           {
               echo '<a href="' . get_category_link($category->cat_ID) . '">' . $category->cat_name . '</a>';
           }
       }
       	}
       }
       ```
   
 * The code works, but in instances where there are multiple subcategories I would
   like to separate those subcategories with a comma. How do I do that? Anyone know?

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [stvwlf](https://wordpress.org/support/users/stvwlf/)
 * (@stvwlf)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/comma-between-subcategory-list/#post-2123136)
 * This should work:
 * replace this
    `if ($category->category_parent == "177")`
 * with this
 *     ```
       $cats = array(177, 213, 309);
       if ( in_array( $category->category_parent, $cats ) ) {
       ```
   
 * if you have one category you can either use
    `if ($category->category_parent 
   == "177")` or
 *     ```
       $cats = array(177);
       if ( in_array( $category->category_parent, $cats ) ) {
       ```
   
 *  Thread Starter [Rose](https://wordpress.org/support/users/eos-rose/)
 * (@eos-rose)
 * [14 years, 11 months ago](https://wordpress.org/support/topic/comma-between-subcategory-list/#post-2123143)
 * Thank you. I actually figured out an alternative using css. 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Comma between subcategory list’ is closed to new replies.

## Tags

 * [child categories](https://wordpress.org/support/topic-tag/child-categories/)
 * [subcategories](https://wordpress.org/support/topic-tag/subcategories/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 2 replies
 * 2 participants
 * Last reply from: [Rose](https://wordpress.org/support/users/eos-rose/)
 * Last activity: [14 years, 11 months ago](https://wordpress.org/support/topic/comma-between-subcategory-list/#post-2123143)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
