Title: PHP slug?
Last modified: August 19, 2016

---

# PHP slug?

 *  [intraspark](https://wordpress.org/support/users/intraspark/)
 * (@intraspark)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/)
 * I am wanting display a link within the entry head of each post like this: [http://domain.com/folder/some-category/postname](http://domain.com/folder/some-category/postname)
 * What I need is the slug (with the category) folder. I just want to add my own“
   [http://domain.com/&#8221](http://domain.com/&#8221); in front of it. The reason
   I am doing this is because I would like them to have the discussion on the post
   in the forums (not in WordPress) instead of in the ‘comments section’.
 * I will keep the directory structure and post name same. I am using permalinks
   and so my usual post links appear like this: [http://domain.com/hello/how-are-you/](http://domain.com/hello/how-are-you/)
 * This is the code that I have so far, it gets me to:
    [http://domain.com/hello/](http://domain.com/hello/)
   I see need the post slug at the end.
 *     ```
       <?php
       foreach((get_the_category()) as $category) {
           echo '<a href="http://xxx.com/forum/' . $category->category_nicename . '/" alt="' . $category->cat_name . '" />';
       }
       ?>Forum</a>
       ```
   
 * I really hope someone can figure this out. Thanks!

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

 *  [Michael](https://wordpress.org/support/users/alchymyth/)
 * (@alchymyth)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1604958)
 * try
 * `$category->slug`
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1604959)
 * Is this what you’re after?
 *     ```
       <?php foreach((get_the_category()) as $category) : ?>
       <a href="http://xxx.com/forum/<?php $category->category_nicename; ?>/<?php echo $post->post_name; ?>">Forum</a>
       <?php endforeach; ?>
       ```
   
 * 🙂
 * **NOTE:** If it shouldn’t produce links for each category, then just select the
   first.
 *     ```
       <?php $first_cat = get_the_category(); $first_cat = $first_cat[0]; ?>
       <a href="http://xxx.com/forum/<?php $first_cat->category_nicename; ?>/<?php echo $post->post_name; ?>">Forum</a>
       ```
   
 *  Thread Starter [intraspark](https://wordpress.org/support/users/intraspark/)
 * (@intraspark)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1604998)
 * [@alchymyth](https://wordpress.org/support/users/alchymyth/) that doesn’t work,
   but thank you.
 * [@mark](https://wordpress.org/support/users/mark/) this works great except it
   is not showing the category.. I am using your 2nd code and it is making the following
   link:
 * [http://xxx.com/forum//name-of-post](http://xxx.com/forum//name-of-post)
 * Please advise.
 * Thanks
 *  Thread Starter [intraspark](https://wordpress.org/support/users/intraspark/)
 * (@intraspark)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1605014)
 * anyone? :/
 *  [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * (@t31os_)
 * [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1605025)
 * Can’t respond in my sleep.. 😉
 * Try the slug as alchymyth suggested alongside?
 *     ```
       <?php $first_cat = get_the_category(); $first_cat = $first_cat[0]; ?>
       <a href="http://xxx.com/forum/<?php $first_cat->slug; ?>/<?php echo $post->post_name; ?>">Forum</a>
       ```
   

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

The topic ‘PHP slug?’ is closed to new replies.

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 5 replies
 * 3 participants
 * Last reply from: [Mark / t31os](https://wordpress.org/support/users/t31os_/)
 * Last activity: [15 years, 8 months ago](https://wordpress.org/support/topic/php-slug/#post-1605025)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
