<?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>web-templates.nuWordpress Hacks  </title>
	<atom:link href="http://www.web-templates.nu/category/wordpress-hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.web-templates.nu</link>
	<description>Just another WordPress weblog</description>
	<lastBuildDate>Sun, 07 Jun 2009 15:18:09 +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>get_category_count()</title>
		<link>http://www.web-templates.nu/2008/09/21/get_category_count/</link>
		<comments>http://www.web-templates.nu/2008/09/21/get_category_count/#comments</comments>
		<pubDate>Sun, 21 Sep 2008 19:30:29 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=41</guid>
		<description><![CDATA[get_category_count() is a Wordpress function to count the posts within a category. It can probably be written in many different ways. Here is my version of the function and should be placed in functions.php in your theme.]]></description>
			<content:encoded><![CDATA[<p>get_category_count() is a Wordpress function to count the posts within a category. It can probably be written in many different ways.<br />
Here is my version of the function and should be placed in functions.php in your theme:</p>
<pre>function wt_get_category_count($input = '') {
	global $wpdb;
	if($input == '')
	{
		$category = get_the_category();
		return $category[0]-&gt;category_count;
	}
	elseif(is_numeric($input))
	{
		$SQL = &quot;SELECT $wpdb-&gt;term_taxonomy.count FROM $wpdb-&gt;terms, $wpdb-&gt;term_taxonomy WHERE $wpdb-&gt;terms.term_id=$wpdb-&gt;term_taxonomy.term_id AND $wpdb-&gt;term_taxonomy.term_id=$input&quot;;
		return $wpdb-&gt;get_var($SQL);
	}
	else
	{
		$SQL = &quot;SELECT $wpdb-&gt;term_taxonomy.count FROM $wpdb-&gt;terms, $wpdb-&gt;term_taxonomy WHERE $wpdb-&gt;terms.term_id=$wpdb-&gt;term_taxonomy.term_id AND $wpdb-&gt;terms.slug='$input'&quot;;
		return $wpdb-&gt;get_var($SQL);
	}
}</pre>
<p>It can be called in three different ways&#8230;</p>
<p>1. Just call the function within The Loop and it will return the count of the first category within the current post.</p>
<pre>&lt;?php echo wt_get_category_count(); ?&gt;</pre>
<p>2. Use the function with an ID and it will return the count of the first category within the post ID.</p>
<pre>&lt;?php echo wt_get_category_count(1); ?&gt;</pre>
<p>3. Use the function with a slug / nicename and it will return the count of the first category within the post slug / nicename.</p>
<pre>&lt;?php echo wt_get_category_count('hello-world'); ?&gt;</pre>
<p>To get all new functions/template tags, install my plugin <a href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/" title="WP Extra Template Tags">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/09/21/get_category_count/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Get Depth &#8211; like is_child() &amp; is_grandchild()</title>
		<link>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/</link>
		<comments>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/#comments</comments>
		<pubDate>Sun, 07 Sep 2008 08:38:29 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=37</guid>
		<description><![CDATA[Is there a function in Wordpress to check the current page depth like is_child(), is_grandchild() or a number for unlimited depth? I could'nt find any so I created one.]]></description>
			<content:encoded><![CDATA[<p>Is there a function in Wordpress to check the current page depth like is_child(), is_grandchild() or a number for unlimited depth? I could&#8217;nt find any so I created one. It is a recursive function which means that it calls itself until it&#8217;s done.</p>
<p>Put the following code to the functions.php in your Wordpress theme folder.</p>
<pre>function wt_get_depth($id = '', $depth = '', $i = 0)
{
	global $wpdb;
	global $post;

	if($depth == '')
	{
		if(is_page())
		{
			if($id == '')
			{
				$id = $post-&gt;ID;
			}
			$depth = $wpdb-&gt;get_var("SELECT post_parent FROM $wpdb-&gt;posts WHERE ID = '".$id."'");
			return wt_get_depth($id, $depth, $i);
		}
	}
	elseif($depth == "0")
	{
		return $i;
	}
	else
	{
		$depth = $wpdb-&gt;get_var("SELECT post_parent FROM $wpdb-&gt;posts WHERE ID = '".$depth."'");
		$i++;
		return wt_get_depth($id, $depth, $i);
	}
}</pre>
<p>Call the function like this in your theme:</p>
<pre>&lt;?php echo wt_get_depth(); ?&gt;</pre>
<p>or if you want to choose a custom page:</p>
<pre>&lt;?php echo wt_get_depth(3); ?&gt;</pre>
<p>Here is a way do use the function:</p>
<pre>&lt;?php if (wt_get_depth() == 2)
{
	echo "This page is a grand grandchild";
}
?&gt;</pre>
<p>If you need a function like is_child() or is_grandchild(), create an is_child() function like this:</p>
<pre>function wt_is_child($id = '')
{
	if(_get_depth($id)&gt;0)
	{
		return true;
	}
}</pre>
<p>or the is_grandchild() function:</p>
<pre>function wt_is_grandchild($id = '')
{
	if(_get_depth($id)&gt;1)
	{
		return true;
	}
}</pre>
<p>and call them like this:</p>
<pre>&lt;?php if (wt_is_child())
{
echo "This is a child page";
}
?&gt;</pre>
<p>or</p>
<pre>&lt;?php if (wt_is_grandchild())
{
echo "This is a grandchild page";
}
?&gt;</pre>
<p>To get all new functions/template tags, install my plugin <a title="WP Extra Template Tags" href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/09/07/get-depth-like-is_child-is_grandchild/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Get ID by Page Name</title>
		<link>http://www.web-templates.nu/2008/09/02/get-id-by-page-name/</link>
		<comments>http://www.web-templates.nu/2008/09/02/get-id-by-page-name/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 18:50:39 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=35</guid>
		<description><![CDATA[The function converts a page name to a page ID. You can use it however you like but in the example I used it with the wp_list_pages() function.]]></description>
			<content:encoded><![CDATA[<p>Functions like <em>wp_list_pages()</em> can be really useful in Wordpress but there are things that I don&#8217;t like.</p>
<p>For include or exclude pages you need the ID. For me it feels better to use the page name instead, simply because the ID can change but the name does not. I have written a function fix this issue.</p>
<p>The function converts a page name to a page ID. You can use it however you like but in the example I used it with the <em>wp_list_pages()</em> function.</p>
<pre>function wt_get_ID_by_page_name($page_name)
{
	global $wpdb;
	$page_name_id = $wpdb-&gt;get_var("SELECT ID FROM $wpdb-&gt;posts WHERE post_name = '".$page_name."'");
	return $page_name_id;
}</pre>
<p>Call the function in your theme:</p>
<pre>&lt;?php wp_list_pages('include='.wt_get_ID_by_page_name('about') ); ?&gt;</pre>
<p>If you just need to display the ID of a page, call the function like this instead:</p>
<pre>&lt;?php echo wt_get_ID_by_page_name('about'); ?&gt;</pre>
<p>To get all new functions/template tags, install my plugin <a title="WP Extra Template Tags" href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/09/02/get-id-by-page-name/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Get Permalink by Name</title>
		<link>http://www.web-templates.nu/2008/09/02/get-permalink-by-name/</link>
		<comments>http://www.web-templates.nu/2008/09/02/get-permalink-by-name/#comments</comments>
		<pubDate>Tue, 02 Sep 2008 17:39:40 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=34</guid>
		<description><![CDATA[If you have a post or a page and need the permalink for it there are serveral solutions. Here are one of them. I created a name to permalink converter called "Get Permalink by Name".]]></description>
			<content:encoded><![CDATA[<p>If you have a post or a page and need the permalink for it there are serveral solutions. Here are one of them. I created a name to permalink converter.</p>
<p>Put the following code to the functions.php in your theme folder.</p>
<pre>function wt_get_permalink_by_name($page_name)
{
	global $post;
	global $wpdb;
	$pageid_name = $wpdb-&gt;get_var(&quot;SELECT ID FROM $wpdb-&gt;posts WHERE post_name = '&quot;.$page_name.&quot;'&quot;);
	return get_permalink($pageid_name);
}</pre>
<p>Call the function like this in your theme:</p>
<pre>&lt;a href=&quot;&lt;?php echo wt_get_permalink_by_name('about'); ?&gt;&quot;&gt;About&lt;/a&gt;</pre>
<p>To get all new functions/template tags, install my plugin <a href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/" title="WP Extra Template Tags">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/09/02/get-permalink-by-name/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>get_the_content() WITH formatting</title>
		<link>http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/</link>
		<comments>http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/#comments</comments>
		<pubDate>Sun, 31 Aug 2008 18:21:40 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=31</guid>
		<description><![CDATA[Normally the get_the_content() tag returns the content without formatting. I found out a solution to make get_the_content() tag return the same content as the_content().]]></description>
			<content:encoded><![CDATA[<p>Normally the <em>get_the_content()</em> tag returns the content without formatting. I found out a solution to make <em>get_the_content()</em> tag return the same content as <em>the_content()</em>.</p>
<pre>&lt;?php echo get_the_content(); ?&gt;
&lt;?php the_content(); ?&gt;</pre>
<p>For me and others that can be a problem if you expect them to behave the same. I looked into the Wordpress core and found a solution. Put this code into your functions.php in your theme folder.</p>
<pre>function get_the_content_with_formatting ($more_link_text = '(more...)', $stripteaser = 0, $more_file = '') {
	$content = get_the_content($more_link_text, $stripteaser, $more_file);
	$content = apply_filters('the_content', $content);
	$content = str_replace(']]&gt;', ']]&amp;gt;', $content);
	return $content;
}</pre>
<p>In your theme, call the function within the loop:</p>
<pre>&lt;?php get_the_content_with_formatting(); ?&gt;</pre>
<p>To get more new functions/template tags, install my plugin <a title="WP Extra Template Tags" href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/08/31/get_the_content-with-formatting/feed/</wfw:commentRss>
		<slash:comments>24</slash:comments>
		</item>
		<item>
		<title>Get Category ID alternative</title>
		<link>http://www.web-templates.nu/2008/08/29/get-category-id-alternative/</link>
		<comments>http://www.web-templates.nu/2008/08/29/get-category-id-alternative/#comments</comments>
		<pubDate>Fri, 29 Aug 2008 11:05:39 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=26</guid>
		<description><![CDATA[Wordpress template tag the_category_id has been deprecated and their recommended method is a bit complicated if you only post in one category at the time. There comes a shorter alternative...]]></description>
			<content:encoded><![CDATA[<p>Wordpress template tag the_category_id has been deprecated which means it will not work now or in the future. The reason for this is that Wordpress now supports multiple categories.</p>
<p>Here is the solution recommended by the Wordpress team. It displays all the category IDs hooked to the post.</p>
<pre>&lt;?php
foreach((get_the_category()) as $category) {
    echo $category-&gt;cat_ID . ' ';
} ?&gt;</pre>
<p>It&#8217;s a bit long and complicated if you just need the first category. The function below is an alternative. It returns the first category ID as a string. Put this function in your functions.php within your theme folder:</p>
<pre>function wt_get_category_ID() {
	$category = get_the_category();
	return $category[0]-&gt;cat_ID;
}</pre>
<p>Call the function below by placing it within <a title="the loop" href="http://codex.wordpress.org/The_Loop">the loop</a> in your theme:</p>
<pre>wt_get_category_ID();</pre>
<p>Short and sweet, is&#8217;nt it?</p>
<p>To get all new functions/template tags, install my plugin <a title="WP Extra Template Tags" href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/08/29/get-category-id-alternative/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Get User Name</title>
		<link>http://www.web-templates.nu/2008/08/27/get-user-name/</link>
		<comments>http://www.web-templates.nu/2008/08/27/get-user-name/#comments</comments>
		<pubDate>Wed, 27 Aug 2008 10:21:51 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=24</guid>
		<description><![CDATA[Sometimes you might need to check if a current user is logged in or not within your theme. I have created a function to get the userdata as a returned string value.]]></description>
			<content:encoded><![CDATA[<p>Sometimes you might need to check if a current user is logged in or not within your theme. This is a way to accomplish that issue.<br />
I have created a function to get the userdata as a returned string value. I recommend you to put in the functions.php file, placed within your current theme folder.</p>
<pre>function wt_get_user_name()
{
	global $userdata;
	get_currentuserinfo();
	return $userdata-&gt;user_login;
}</pre>
<p>Now you can print it out to see that you get a string value (this will only work when you are logged in). Put the code below somewhere in your theme to do so.</p>
<pre>&lt;?php echo 'Welcome ' . wt_get_user_name(); ?&gt;</pre>
<p>To check if a specific user is logged in try this:</p>
<pre>&lt;?php
if(wt_get_user_name() == 'Adam')
{
	echo 'You have all the rights to visit this page!'
}
else
{
	echo 'You do not have permission to view this page!'
}
?&gt;</pre>
<p>To get all new functions/template tags, install my plugin <a title="WP Extra Template Tags" href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/08/27/get-user-name/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Delete Post Link</title>
		<link>http://www.web-templates.nu/2008/08/25/delete-post-link/</link>
		<comments>http://www.web-templates.nu/2008/08/25/delete-post-link/#comments</comments>
		<pubDate>Mon, 25 Aug 2008 13:34:06 +0000</pubDate>
		<dc:creator>jens</dc:creator>
				<category><![CDATA[Wordpress Hacks]]></category>

		<guid isPermaLink="false">http://www.web-templates.nu/?p=20</guid>
		<description><![CDATA[I have created a function called "Delete Post Link". If you are logged in you will see a link which allows you to delete the current page or post, even without visiting admin.]]></description>
			<content:encoded><![CDATA[<p>In most Wordpress themes, if you are logged in, there is an &#8220;Edit Post&#8221; link. That way you can go directly into edit the current post.</p>
<p>I have created a function called &#8220;Delete Post Link&#8221;. If you are logged in you will see a link which allows you to delete the current page or post, even without visiting admin.</p>
<p><strong>Warning! You should be very careful using this function!</strong></p>
<pre>function wp_delete_post_link($link = 'Delete This', $before = '', $after = '')
{
	global $post;
	if ( $post-&gt;post_type == 'page' ) {
		if ( !current_user_can( 'edit_page', $post-&gt;ID ) )
			return;
	} else {
		if ( !current_user_can( 'edit_post', $post-&gt;ID ) )
			return;
	}
	$link = &quot;&lt;a href='&quot; . wp_nonce_url( get_bloginfo('url') . &quot;/wp-admin/post.php?action=delete&amp;amp;post=&quot; . $post-&gt;ID, 'delete-post_' . $post-&gt;ID) . &quot;'&gt;&quot;.$link.&quot;&lt;/a&gt;&quot;;
	echo $before . $link . $after;
}</pre>
<p>I recommend you to put the function into your functions.php file in your theme folder. When done just put the function into your theme like this:</p>
<pre>wp_delete_post_link('Delete This', '&lt;p&gt;', '&lt;/p&gt;')</pre>
<p>To get all new functions/template tags, install my plugin <a href="http://www.web-templates.nu/2008/08/25/wp-extra-template-tags/" title="WP Extra Template Tags">WP Extra Template Tags.</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.web-templates.nu/2008/08/25/delete-post-link/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>
