smbaker
Member
Posted 2 years ago #
Let's say my wordpress site is at http://mysite.com/wordpress. I have a page called "foo" and it has a child called "bar". My permalinks are set to /%pagename. The full permalink of bar would be:
http://mysite.com/wordpress/foo/bar
I can get this full permalink using get_permalink(id_of_bar). However, let's say I want only the part of the permalink that is relative to the inside of the wordpress site. That would be:
/foo/bar
(I'm assuming this is the link that is internally redirected to index.php when retrieving the page; i.e. http://mysite.com/wordpress/index.php?pagename=/foo/bar)
How do I get just this part of the permalink?
Scott
richarduk
Member
Posted 2 years ago #
http://codex.wordpress.org/Template_Tags/get_permalink
get_permalink will give you the url for PHP to process. Not sure what you'd do next - there'll be some simple PHP somewhere to strip out the top-level domain name.
try this global variable.
$url_slug = $_SERVER['REQUEST_URI'];
Parse url would be suited in this case, assuming you just want to catch the canonical parts of the URL, ie /page/subpage/
$url_endpoint = get_permalink(ID_HERE);
$url_endpoint = parse_url( $url_endpoint );
$url_endpoint = $url_endpoint['path'];
echo $url_endpoint;
http://www.php.net/manual/en/function.parse-url.php
See the page above, the array stored by parse_url stores various pieces of the URL..
Hope that helps.
brilliant, hei, i got a new trick ;)