[wp-hackers] Get query variables and tags

Mike Schinkel mikeschinkel at newclarity.net
Mon Feb 2 23:54:42 GMT 2009


For #1

	function get_url_path() {
		static $path;
		if (!isset($path)) {
			$path = strtolower(trim($_SERVER['REQUEST_URI'],'/'));
			$path = explode('?',$path);
			$path = $path[0];
		return $path;

	function get_last_url_segment() {
		static $last_segment;
		if (!isset($last_segment)) $last_segment = array_pop(explode('/', self::get_url_path()));
		return $last_segment;

For #2 (I think)

    $q = new WP_Query();

See: http://codex.wordpress.org/Template_Tags/query_posts 
Also: http://weblogtoolscollection.com/archives/2008/04/13/define-your-own-wordpress-loop-using-wp_query/


-Mike Schinkel

----- Original Message -----
From: "Ade Walker" <photofantaisie at gmail.com>
To: wp-hackers at lists.automattic.com
Sent: Monday, February 2, 2009 6:38:26 PM GMT -05:00 US/Canada Eastern
Subject: [wp-hackers] Get query variables and tags

Hi all,

I would be very grateful to get a pointer or two for this, please.

I have a single post template with a sidebar which is to be populated with
links to other posts (from the same category). Each post has various tags
assigned to it. If the user clicks a tag, which are listed on the page using
the_tags(), I want the sidebar list of posts to only reflect posts which
have the same tag.

I was thinking that if I could access the query string and identify which
tag had been clicked, I could then run a wp_query to pull posts with the
same tag.

So, my questions are (1) how do I grab the query string to identify which
tag had been clicked, and (2) would I use get_the_tags() to filter the
results of the wp_query?

I have a feeling I'm either oversimplifying what is required - or
over-complicating it! So any pointers would be very gratefully received.

Thanks in advance.

wp-hackers mailing list
wp-hackers at lists.automattic.com

More information about the wp-hackers mailing list