Current URL path variable (2 posts)

  1. willee
    Posted 1 year ago #

    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:


    But lets say that I have a page within /accounting like this:


    Using the $pagename method will only provide me with this:


    My preferred solution would be to use something like $pagename and get the full path.

  2. willee
    Posted 1 year ago #


    $path = substr( get_permalink(), strlen( home_url('/') ) );

    Gets the permalink and strips home root path from it

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.