Title: Small PHP problem
Last modified: August 20, 2016

---

# Small PHP problem

 *  Resolved [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/)
 * I have the following code which basically gets the name and link of the sub category
   of category ID 1 and then echoes that out. I’m sure this is a very very simple
   PHP issue but I don’t know how to get it so that all of it is contained within
   the link. So it currently looks like this:
 * View all Art projects (with only “Art” being the link) whereas I want all of “
   View all Art projects” to be the link
 *     ```
       <li><?php _e( 'View all', 'mytheme' ); ?> <?php
       foreach((get_the_category()) as $childcat) {
       if (cat_is_ancestor_of(1, $childcat)) {
       echo '<a href="'.get_category_link($childcat->cat_ID).'">';
        echo $childcat->cat_name . '</a>';
       }}
       ?> <?php _e( 'Projects', 'mytheme' ); ?></li>
       ```
   
 * Really hope someone can help with this?

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

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841508)
 * Everything to be included in a link needs to go just before the closing `</a>`
   tag.
 * Please try this:
 *     ```
       <li>
          <?php foreach((get_the_category()) as $childcat) {
             if (cat_is_ancestor_of(1, $childcat)) {
                echo '<a href="'.get_category_link($childcat->cat_ID).'">';
                _e( 'View all', 'mytheme' );
                echo $childcat->cat_name;
                _e( 'Projects', 'mytheme' );
                echo '</a>';
             }
          }
          ?>
       </li>
       ```
   
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841510)
 * Thanks so much for this.
 * Just one question. It now doesn’t have any spacing i.e. it comes out as:
 * View allArtProjects
 * How do I go about adding the spaces?
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841511)
 * Sorry about that. Just add a space in ‘View all’ and ‘Projects’ like this: ‘View
   all ‘ and ‘ Projects’.
 *  Thread Starter [greencode](https://wordpress.org/support/users/greencode/)
 * (@greencode)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841513)
 * Sorry, one of those days – very obvious what I should have done! Thanks so much
   for your help with this – really appreciated.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841515)
 * If your problem has been solved, please use the dropdown on the right to mark
   this topic ‘Resolved’ so that anyone else with this question can see that there
   is a solution.

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

The topic ‘Small PHP problem’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 2 participants
 * Last reply from: [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/small-php-problem/#post-2841515)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
