How can I get the tag of a tag page, like http://www.domain.com/tag/my-tag so it return my-tag? Is there any function for this? Thanks.
Here is how the concept of that works: <?php $url = 'http://www.google.com/path/test/two'; # /path/test/two $parsed = parse_url($url, PHP_URL_PATH); # path/test/two $fix = substr($parsed, 1, strlen($parsed) -1); $parts = explode('/', $fix); /* Array ( [0] => path [1] => test [2] => two ) */ PHP: And this next one is a simplified function with comments. <?php /*********************** * URI Segment ************************ * Written by Joel Larson (Coded Caffeine) * Author URL: http://thejoellarson.com/ * Date: 26.12.09 ***********************/ /** * uri_segment() * * Parses the URI segments from a URL. * * @access public * @param int * @param string * @return string */ function uri_segment($id = 0, $segment = NULL) { # Parse the segments into one/two/three $path = substr(parse_url($segment, PHP_URL_PATH), 1, strlen($segment)-1); # Explode the forward slash, making a uri segment array. $parts = explode('/', $path); # Return the specified array ID. (Starts at 0) return $parts[$id]; } PHP: This is how it's called: <?php #URL $url = 'http://example.com/segment/one/two/three'; # Returns 'one' $segment = uri_segment(1, $url); PHP:
That will work, but do you know how to find the tag at wordpress? Sorry, I guess I didn't give clear description.
If you need this in your template files, it's possible to add the function to function.php and use it. To my knowledge, there isn't a pre-existing function for URI segments.