Title: Current URL path variable
Last modified: August 21, 2016

---

# Current URL path variable

 *  [willee](https://wordpress.org/support/users/willee/)
 * (@willee)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/current-url-path-variable/)
 * I am using a page template to display a folders contents depending on which page
   someone is on. Right now this method is working for top level paths, but not 
   for anything nested. I understand why it isn’t working, but I am not sure how
   to fix it. Here is an example of what I am doing now:
 * `$dir = "wp-content/uploads/Docs/".$pagename;`
 * So that will give me the correct path to the top level pages, but anything below
   them will not work. I know the easy solution would just to keep all folders at
   the base level in the upload directory, but I want my server side files to make
   sense also. How a url using `$pagename` looks now:
 * [http://example.com/accounting](http://example.com/accounting)
 * But lets say that I have a page within /accounting like this:
 * [http://example.com/accounting/accounts-receivable](http://example.com/accounting/accounts-receivable)
 * Using the `$pagename` method will only provide me with this:
 * [http://example.com/accounts-receivable](http://example.com/accounts-receivable)
 * My preferred solution would be to use something like `$pagename` and get the 
   full path.

Viewing 1 replies (of 1 total)

 *  Thread Starter [willee](https://wordpress.org/support/users/willee/)
 * (@willee)
 * [12 years, 2 months ago](https://wordpress.org/support/topic/current-url-path-variable/#post-4776233)
 * Solution:
 * `$path = substr( get_permalink(), strlen( home_url('/') ) );`
 * Gets the permalink and strips home root path from it

Viewing 1 replies (of 1 total)

The topic ‘Current URL path variable’ is closed to new replies.

 * 1 reply
 * 1 participant
 * Last reply from: [willee](https://wordpress.org/support/users/willee/)
 * Last activity: [12 years, 2 months ago](https://wordpress.org/support/topic/current-url-path-variable/#post-4776233)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
