<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Dyason Hat &#187; code</title>
	<atom:link href="http://www.dyasonhat.com/category/code/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dyasonhat.com</link>
	<description>code is beauty</description>
	<lastBuildDate>Thu, 07 Jan 2010 14:41:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Wordpress: Get current context url</title>
		<link>http://www.dyasonhat.com/code/wordpress-get-current-context-url/</link>
		<comments>http://www.dyasonhat.com/code/wordpress-get-current-context-url/#comments</comments>
		<pubDate>Tue, 02 Dec 2008 08:54:07 +0000</pubDate>
		<dc:creator>DyasonHat</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[context url]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://www.dyasonhat.com/?p=77</guid>
		<description><![CDATA[Edit: 10 Dec 2008. Changed select term_taxonomy_id to term_id.
There are many times when developing a plugin that I&#8217;ve wanted to easily get the url of the current context eg. if I&#8217;m in a category page I want the url of that page, and the same for tags archives etc.
The following function does this quite nicely.

&#60;/code&#62;

function [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #ff0000;">Edit: 10 Dec 2008. Changed select term_taxonomy_id to term_id.</span></p>
<p>There are many times when developing a plugin that I&#8217;ve wanted to easily get the url of the current context eg. if I&#8217;m in a category page I want the url of that page, and the same for tags archives etc.</p>
<p>The following function does this quite nicely.</p>
<p><code>
<pre class="brush: php;">&lt;/code&gt;

function get_current_context_url(){
global $wp_query;
global $wpdb;

$url = '';
if (is_category()) {
$cat_id = $wp_query-&gt;query_vars['cat'];
$url = get_category_link($cat_id);
}
elseif (is_tag()) {
$tag_name = $wp_query-&gt;query_vars['tag'];
$tag_id = $wpdb-&gt;get_var(&quot;SELECT &quot;.$wpdb-&gt;terms.&quot;.term_id FROM $wpdb-&gt;term_taxonomy
LEFT JOIN $wpdb-&gt;terms
ON (&quot;.$wpdb-&gt;term_taxonomy.&quot;.term_id = &quot;.$wpdb-&gt;terms.&quot;.term_id)
WHERE &quot;.$wpdb-&gt;terms.&quot;.slug = '$tag_name'
AND &quot;.$wpdb-&gt;term_taxonomy.&quot;.taxonomy = 'post_tag'
LIMIT 1&quot;);
$url = get_tag_link($tag_id);
}
elseif (is_author()) {
$author_id = $wp_query-&gt;query_vars['author'];
$url = get_author_posts_url($author_id);
}
elseif (is_date()) {
$year = $wp_query-&gt;query_vars['year'];
$month = $wp_query-&gt;query_vars['monthnum'];
$day = $wp_query-&gt;query_vars['day'];

if ($wp_query-&gt;query_vars['day']) {
$url = get_day_link( $year,  $month,  $day);
}
elseif ($wp_query-&gt;query_vars['monthnum']) {
$url = get_month_link( $year,  $month,  $day);
}
elseif ($wp_query-&gt;query_vars['year']) {
$url = get_year_link( $year,  $month,  $day);
}
}
else {
$url = get_bloginfo('url');
}

//ensure trailing slash
if (&quot;/&quot; != substr($url, -1)) {
$url = $url . &quot;/&quot;;
}
return $url;
}

&lt;code&gt;</pre>
<p></code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dyasonhat.com/code/wordpress-get-current-context-url/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

