Title: Problem with separator
Last modified: August 20, 2016

---

# Problem with separator

 *  Resolved [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/)
 * I’m using the following in my query to display the child categories
 *     ```
       <?php
       foreach((get_the_category()) as $childcat) {
       if (cat_is_ancestor_of(1, $childcat)) {
       echo $sep,'<a href="'.get_category_link($childcat->cat_ID).'">',$childcat->cat_name,'</a>';
       $sep = ' / ';
       }}
       ?>
       ```
   
 * So this is then displaying as follows:
 * Category a / Category b / Category c
 * The problem is when there’s more than one post on the page the next lot show 
   as
 * / Category a / Category b / Category c
 * i.e. it’s just continuing to add the forward slash and not simply starting the
   query again.
 * Basically I need it so the separator does not show at the beginning or end of
   the category list.
 * Any help would be greatly appreciated.

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/#post-2278415)
 * there is a comma after `$sep` which might break the code – should be a dot;
 * try:
 *     ```
       <?php
       foreach((get_the_category()) as $childcat) {
       if (cat_is_ancestor_of(1, $childcat)) {
       echo $sep.'<a href="'.get_category_link($childcat->cat_ID).'">',$childcat->cat_name,'</a>';
       $sep = ' / ';
       }}
       ?>
       ```
   
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/#post-2278417)
 * Thanks for that – I’ve changed the comma to a full stop but it hasn’t had any
   effect to the original issue.
 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/#post-2278419)
 * ok, i get it 😉
 * before the foreach, you need to reset the separator to an epmty space:
 * `$sep = '';`
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/#post-2278422)
 * Perfect – thanks so so much for your help. Really appreciated.

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

The topic ‘Problem with separator’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [greencode](https://wordpress.org/support/users/greencode/)
 * Last activity: [14 years, 8 months ago](https://wordpress.org/support/topic/problem-with-separator/#post-2278422)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
