<?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>WP Engineer &#187; template tag</title>
	<atom:link href="http://wpengineer.com/tag/template-tag/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Sun, 22 Jan 2012 13:32:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Search Form in WP Nav Menu</title>
		<link>http://wpengineer.com/2244/search-form-in-wp-nav-menu/</link>
		<comments>http://wpengineer.com/2244/search-form-in-wp-nav-menu/#comments</comments>
		<pubDate>Fri, 29 Jul 2011 08:41:15 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Search]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2244</guid>
		<description><![CDATA[The WP Nav Menu is very popular and WordPress users love to implement their content in the navigation that way. Many users also like to have a search field in their navigation. In this context I found some horrible written solutions to implement the search field in the navigation. That's why I thought I write [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://codex.wordpress.org/Function_Reference/wp_nav_menu" title="Doku im Codex">WP Nav Menu</a> is very popular and WordPress users love to implement their content in the navigation that way. Many users also like to have a search field in their navigation. In this context I found some horrible written solutions to implement the search field in the navigation. That's why I thought I write a simple yet efficient solution to have the search field in your navigation. <span id="more-2244"></span></p>
<p>For this solution I'm using the default search function - <code>get_search_form()</code>. If you use it on another spot as well, please pay attention to the stylesheet. Otherwise the following snippet is sufficient to implement the search field in your navigation.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/search-wp-nav-menu.png" alt="" title="search-wp-nav-menu" width="600" height="223" class="aligncenter size-full wp-image-2245" /></p>
<p>This function and the call belongs into <code>functions.php</code> of the theme and the adjustment of the stylesheet in the according file of the theme, most of the time it is <code>style.css</code>.</p>
<pre>
function fb_add_search_box ( $items, $args ) {

	// only on primary menu
	if( &#039;primary&#039; === $args -&gt; theme_location )
		$items .= &#039;&lt;li class=&quot;menu-item menu-item-search&quot;&gt;&#039; . get_search_form( FALSE ) . &#039;&lt;/li&gt;&#039;;

	return $items;
}
add_filter( &#039;wp_nav_menu_items&#039;, &#039;fb_add_search_box&#039;, 10, 2 );
</pre>
<p>If you like to implement the search form only in a specific navigation; you just need to call the entry <code>theme_location</code> of the argument array. If it's the menu with the string n, then ... - an example:<br />
<code>if( 'primary' === $args -&gt; theme_location )</code></p>
<p><img src="http://wpengineer.com/wp-content/uploads/search-wp-nav-menu2.png" alt="" title="search-wp-nav-menu2" width="514" height="341" class="aligncenter size-full wp-image-2246" /></p>
<p>The key of the call is defined in your theme, therefore easy to find in the backend, as you can see in the screenshot above. Have fun with it!<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2244/search-form-in-wp-nav-menu/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Adding Input Fields To Comment Form</title>
		<link>http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/</link>
		<comments>http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/#comments</comments>
		<pubDate>Tue, 03 May 2011 09:22:35 +0000</pubDate>
		<dc:creator>Latz</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[comment form]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2214</guid>
		<description><![CDATA[Most comment forms contain the same input fields: Name, Email, URL and the comment text field. This is sufficient for most use cases but there are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains [...]]]></description>
			<content:encoded><![CDATA[<p>Most comment forms contain the same input fields: Name, Email, URL and the comment text field. This is sufficient for most use cases but there are situations where you might want to know a bit more about your commenter: their age, the city they live in, or the color of their underwear. This article explains how to add an input field, store the data in the database and how to display the additional data in your blog if your theme uses the <code>comment_form()</code> function provided by WordPress.<span id="more-2214"></span></p>
<h3>Adding the input field</h3>
<p>As an example we will add an input field asking for the city the commenter lives in. Additionally the field will be marked as mandatory.</p>
<p>To add an additional input field you have to modify the comment form defaults by setting a filter for the function <code>comment_form_defaults</code>:</p>
<pre>
add_filter( &#039;comment_form_defaults&#039;, &#039;change_comment_form_defaults&#039;);
</pre>
<p>For adding the new input field after the email field you need to extend the default "Email" input field:</p>
<pre>
function change_comment_form_defaults( $default ) {
    $commenter = wp_get_current_commenter();
    $default&#091; &#039;fields&#039; &#093;&#091; &#039;email&#039; &#093; .= &#039;&lt;p class=&quot;comment-form-author&quot;&gt;&#039; .
        &#039;&lt;label for=&quot;city&quot;&gt;&#039;. __(&#039;City&#039;) . &#039;&lt;/label&gt;
        &lt;span class=&quot;required&quot;&gt;*&lt;/span&gt;
        &lt;input id=&quot;city&quot; name=&quot;city&quot; size=&quot;30&quot; type=&quot;text&quot; /&gt;&lt;/p&gt;&#039;;
    return $default;
}
</pre>
<p>Basically this is the same markup used to create the author field with modified values for <code>label</code>, <code>name</code>, and <code>id</code> and "<code>&lt;span class="required"&gt;*&lt;/span&gt;"</code> added to mark the field as mandatory (only visually).</p>
<h3>Storing the data in the database</h3>
<p>Storing the value of the new field is quite simple since WordPress already contains a table in the database called <code>commentmeta</code> for storing exactly this type of data called meta data.<br />
The usage of this table is straightforward since WordPress provides the two functions <code>add_comment_meta()</code> and <code>get_comment_meta()</code>:</p>
<pre>
add_comment_meta($comment_id, $meta_key, $meta_value, $unique = false)
get_comment_meta( $comment_id, $meta_key, $single = false )
</pre>
<p>To store the meta data together with the other comment data an action needs to be added:</p>
<pre>
add_action( &#039;comment_post&#039;, &#039;save_comment_meta_data&#039; );

function save_comment_meta_data( $comment_id ) {
    add_comment_meta( $comment_id, &#039;city&#039;, $_POST&#091; &#039;city&#039; &#093; );
}
</pre>
<p>To make the city field mandatory the script needs to check if the user had entered some text before the data is stored. WordPress provides a filter named <code>preprocess_comment</code> which can be used to verify the data:</p>
<pre>
add_filter( &#039;preprocess_comment&#039;, &#039;verify_comment_meta_data&#039; );

function verify_comment_meta_data( $commentdata ) {
    if ( ! isset( $_POST&#091;&#039;city&#039;&#093; ) )
        wp_die( __( &#039;Error: please fill the required field (city).&#039; ) );
    return $commentdata;
}
</pre>
<p>The data is not actually processed but it is tested if the field <code>$_POST['city']</code> contains any data. If there is no data the script will die with an error message otherwise the comment data will be returned unaltered.<br />
Alternative ist the Action Hook <code>pre_comment_on_post</code> usable.</p>
<h3>Retrieving and displaying the data</h3>
<p>To retrieve the data from the database WordPress provides the function <code>get_comment_meta</code>. To avoid to modify the theme template the city name is attached to the author name by using the filter <code>get_comment_author_link</code>:</p>
<pre>
add_filter( &#039;get_comment_author_link&#039;, &#039;attach_city_to_author&#039; );

function attach_city_to_author( $author ) {
    $city = get_comment_meta( get_comment_ID(), &#039;city&#039;, true );
    if ( $city )
        $author .= &quot; ($city)&quot;;
    return $author;
}
</pre>
<h3>Advanced usage</h3>
<p>You might have noticed that both functions <code>add_comment_meta()</code> and <code>get_comment_meta()</code> contain parameters that haven't been explained yet, namely <code>$unique</code> and <code>$single</code>.</p>
<p>The <code>$unique</code> parameter controls whether you can add multiple data field with the same key name for the same comment_id. But why would you want do such a thing?<br />
Let's assume you want to allow the user to add multiple cities separated by commas. Surely you can store the whole string in a single table row but that would make the data hard to handle if you want to use it in a different context and it simply conflicts with basic database principles. So the input data will be split and each city is stored in its own dataset:</p>
<pre>
function save_comment_meta_data( $comment_id ) {
    $cities = explode( &#039;,&#039;, $_POST&#091; &#039;city&#039; &#093; );
    foreach ( $cities as $city )
       echo add_comment_meta( $comment_id, &#039;city&#039;, $city, false );
}
</pre>
<p>If the user enters e.g. three city names all three are stored with the keyname <code>city</code>. If the parameter <code>unique</code> would have been set to <code>true</code> only the first city would have been stored because the parameter prevents the storage attempts of the last two city names.</p>
<p>When retrieving the data with <code>get_comment_meta</code> the parameter <code>$single</code> comes into view. If it is set to <code>false</code> the function does not return a single value but an array of values.</p>
<pre>
function attach_city_to_author( $author ) {
    $cities = get_comment_meta( get_comment_ID(), &#039;city&#039;, false );
    if ( $cities ) {
        $author .= &#039; ( &#039;;
        foreach ( $cities as $city )
            $author .= $city . &#039; &#039;;
        $author .= &#039;)&#039;;
    }
    return $author;
}
</pre>
<h3>Modifying the meta data</h3>
<p>There might be situations where you want to change the meta data stored in the database. As expected WordPress provides a function for this called <code>update_comment_meta()</code>:</p>
<pre>
update_comment_meta( $comment_id, $meta_key, $meta_value, $prev_value );
</pre>
<p>To modify a value you use the function the same way you use <code>add_comment_meta</code>:</p>
<pre>
$new_city = &quot;Timbuktu&quot;;
update_comment_meta( $comment_id, &#039;city&#039;, $new_city );
</pre>
<p>If the <code>$meta_key</code> does not exist the function adds the meta data to the database. But what is the parameter <code>$prev_value</code> used for?<br />
As noticed above you can store more than one value with the same meta key for a single comment. The code snippet above would change all values with the key 'city'. If you set the parameter <code>$prev_value</code> to the value that is to be modified the function will do exactly what is intended:</p>
<pre>
$old_city = &quot;Berlin&quot;;
$new_city = &quot;Timbuktu&quot;;
update_comment_meta( $comment_id, &#039;city&#039;, $new_city, $old_city );
</pre>
<h3>Behind the scenes</h3>
<p>The structure of the commentmeta table is quite simple:</p>
<table align="center">
<tr>
<th>meta_id</th>
<th>comment_id</th>
<th>meta_key</th>
<th>meta_value</th>
</tr>
<tr>
<td>bigint(20)</td>
<td>bigint(20)</td>
<td>varchar(255)</td>
<td>longtext</td>
</tr>
</table>
<p>The <code>meta_id</code> is an auto-incremented ID and <code>comment_id</code> is of course the ID of the comment. The actual data is stored in the <code>meta_key</code> and <code>meta_value</code> fields, containing the keyname (in our case 'city') and the actual value (the name of the city the user entered). Example:</p>
<table>
<tr>
<th>meta_id</th>
<th>comment_id</th>
<th>meta_key</th>
<th>meta_value</th>
</tr>
<tr>
<td>45</td>
<td>76</td>
<td>city</td>
<td>Berlin</td>
</tr>
<tr>
<td>46</td>
<td>77</td>
<td>city</td>
<td>Hamburg</td>
</tr>
<tr>
<td>47</td>
<td>78</td>
<td>city</td>
<td>Hamburg</td>
</tr>
<tr>
<td>48</td>
<td>78</td>
<td>city</td>
<td>Berlin</td>
</tr>
<tr>
<td>49</td>
<td>78</td>
<td>city</td>
<td>Mainz</td>
</tr>
</table>
<p>The comments with the ID 76 and 77 contain meta data with only one value assigned to the key 'city' whereas the comment with the ID 78 got three different values with the same key.</p>
<h3>Look it up</h3>
<p>If you want to look up the {add|get|update}_meta_data functions in the core you can find them in <code>.../wp-includes/comment.php</code>.<br />
The default values of the comment form which are modified above are defined in <code>../wp-includes/comment-form.php</code> in the function <code>comment_form()</code>.</p>
<h3>Source code</h3>
<p>Download the complete sources of the examples above:</p>
<ul>
<li>via Gist: <a href="https://gist.github.com/953193">Single value meta data</a></li>
<li>via Gist: <a href="https://gist.github.com/953195">Multi value meta data</a></li>
</ul>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2214/adding-input-fields-to-the-comment-form/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>WordPress Template Tag Reference Guide</title>
		<link>http://wpengineer.com/2108/wordpress-template-tag-reference-guide/</link>
		<comments>http://wpengineer.com/2108/wordpress-template-tag-reference-guide/#comments</comments>
		<pubDate>Fri, 03 Dec 2010 09:51:13 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress News]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[WP3.0]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2108</guid>
		<description><![CDATA[There is a new, nicely organized, Reference Guide for Template Tags in WordPress 3.0. This is a nice resource next to the Codex for Template Tags. Visual nicely done and containing only the minimum information, the guide is a perfect tool when developing Themes. Have fun using it. &#169; WP Engineer Team, All rights reserved [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-032.jpg" alt="" title="WordPress-Christmas-2010-03" width="400" height="267" class="aligncenter size-full wp-image-2111" />There is a new, nicely organized, <a href="http://www.dbswebsite.com/design/wordpress-reference/V3/">Reference Guide for Template Tags</a> in WordPress 3.0. This is a nice resource next to the Codex for Template Tags. Visual nicely done and containing only the minimum information, the guide is a perfect tool when developing Themes. Have fun using it.</p>
<p><a href="http://www.dbswebsite.com/design/wordpress-reference/V3/"><img src="http://wpengineer.com/wp-content/uploads/template-tag-reference-300x277.png" alt="" title="template-tag-reference" width="300" height="277" class="aligncenter size-medium wp-image-2109" /></a></p>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2108/wordpress-template-tag-reference-guide/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Understand WordPress Child Theme</title>
		<link>http://wpengineer.com/2045/understand-wordpress-child-theme/</link>
		<comments>http://wpengineer.com/2045/understand-wordpress-child-theme/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 15:13:48 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>
		<category><![CDATA[WP3.0]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2045</guid>
		<description><![CDATA[With version 3.0 of WordPress, the much anticipated feature of Child Themes was integrated or some might say it was improved, since it was actually possible to use it. I like to show you an example based on the new default Theme TwentyTen how you use it. Another example can be found in my WP [...]]]></description>
			<content:encoded><![CDATA[<p>With version 3.0 of WordPress, the much anticipated feature of <a href="http://codex.wordpress.org/Child_Themes">Child Themes</a> was integrated or some might say it was improved, since it was actually possible to use it. I like to show you an example based on the new default Theme <a href="http://wordpress.org/extend/themes/twentyten">TwentyTen</a> how you use it. Another example can be found in my <a href="http://wpbasis.de">WP Basis-Theme</a> (<a href="http://code.google.com/p/wp-basis-theme/source/browse/#svn/trunk/basis-child-example%3Fstate%3Dclosed">SVN</a>); currently not HTML 5 version.</p>
<p>The function of the Child Themes can be applied basically in every theme and the new features facilitate access and creation of a Child Themes. Before there were also possibilities to change a Theme without changing the actual files of the theme. With the support of Child Themes this is now completely independent and we can use a theme that can be updated without a problem, and you can still realize your own ideas.</p>
<p>Other blogs already mentioned Child Themes but I've found so far only posts where they just talking about the activation and modification of the style sheet. Therefore, I would like to comment this subject only briefly, which is quite simple and then show the different possibilities in terms of template files.<br />
<span id="more-2045"></span></p>
<h4>Advantages of Child Theme</h4>
<p>More or less every administrator is trying to create an individual design for his WordPress system. This does not require to create a special theme from scratch. Very often, a free or commercial Theme is used and then adapted to your needs. Many Themes have different options but are not sufficient for customizing. If you want to adjust the individual design, such as the layout of a category, that requires some changes of the theme. No matter how extensive, an update of a Theme is no longer feasible without problems. Here the Child Themes come into consideration.</p>
<p>With a Child Theme, a Theme can be adjusted or you can use a Theme as a "Framework" and implement completely your own ideas. No matter how extensive, the real Theme remains intact and can undergo an update.</p>
<h4>Disadvantages of Child Theme</h4>
<p>Often "Framework" Themes are very comprehensive and with many features, sometimes it has a steep learning curve and customizing can cost a lot of effort and time. Even though with Child Themes.<br />
A major disadvantage is also the performance, because WordPress have to look into two areas according to the template and get the according files.<br />
Furthermore style sheets, if you build on them, are usually implemented via @-rule, which has <a href="http://www.stevesouders.com/blog/2009/04/09/dont-use-import/">disadvantages in performance</a>.</p>
<p>In all the negative points, it depends on skill and knowledge of the developer and how the Theme or Child Theme is created. Thus you can weaken the negative arguments I pointed out. Important: The new function should be carefully considered before using it. But with Child Themes you don't have to touch the basic Theme and yet you can make adjustments easily.</p>
<h3>Create Child Theme</h3>
<p>Enough said, let's start with the example based on the Theme TwentyTen and create an adjusted Theme - I will call it <em>TwentyTenJump</em> <img src='http://wpengineer.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>In the first step, a new folder is created in which we put all the template files, images, scripts and style sheets - what is principally needed for the Child Theme. In this example, the folder is <em>twentytenjump</em>. To create a Child Theme and make this apparent to WordPress, you simply need <code>style.css</code> within the new folder with several strings in a comment.</p>
<p>Within <code>style.css</code> it looks like this.</p>
<pre lang="css">
@charset &quot;UTF-8&quot;;

/**
 * Theme Name:     TwentyTenJump
 * Theme URI:      http://bueltge.de/?p=1192
 * Description:    Child theme for the Twenty Ten theme. Realized for a small tutorial to child themes in WordPress.
 * Author:         Frank Bültge
 * Author URI:     http://bueltge.de/
 * Template:       twentyten
 * Version:        0.1.0
 */

@import url(&#039;../twentyten/style.css&#039;);
</pre>
<p>Important are the key <em>Theme Name</em> and <em>Template</em>. The key <code>Template</code> points to the <strong>folder name</strong> of the Theme, which is considered as a basis - in that instance, the Theme Twentyten.</p>
<p>I now have the following structure within the installation of WordPress.</p>
<ul>
<li><code>wp-content</code>
<ul>
<li><code>themes</code>
<ul>
<li><code>twentyten</code></li>
<p> (Basic Theme, including all template files)</p>
<ul>
<li><code>style.css</code></li>
<li><code>index.php</code></li>
<li>...</li>
</ul>
<li><code>twentytenjump</code>
<ul>
<li><code>style.css</code> (must satisfy these name convention: <i>style.css</i>)</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Thus, the first requirements are in place and you can select the new Theme in the backend of WordPress.<br />
<strong>Note:</strong> the reference to the Basic Theme is not very conspicuous, so that you might forget the dependency. So that's why you should always check before you delete a Theme. On the used Theme, there is no indication that a different Theme as a Child Theme is using this Theme.</p>
<h4>Working on the style sheet</h4>
<p>From now you can put any changes in your style sheet. Also, of course, you can remove the call to the style sheet <code>@import url('../twentyten/style.css');</code> from the Basic Theme and you can build your own style sheet completely.</p>
<p>You use the template files, the structure and PHP know-how of the Basic Theme, in which case is Twenty Ten. You deal exclusively with the design. For example, this could be the simplest case, a change in color of the background and alternatively a completely separate design will be created.</p>
<h4>Replace templates</h4>
<p>The functionality of the Child Theme includes more than just changing the appearance. You can replace existing template files of the Basic Themes. WordPress looks first in the Child Theme and then in the Basic Theme for possible templates. WordPress runs through the <a href="http://codex.wordpress.org/File:Template_Hierarchy.png">hierarchy of template files</a>.</p>
<p>At many points in your Theme you can intervene via Hook, which might be not very easy and complicated for some users. Thus not infrequently the output of title in <code>head</code> of a web site will be replaced with own functions or Plugins. You can either edit the title via Hook or control the output of a function. For example, the title should now be displayed with a function of a Plugin. In that case you have to adjust the <code>header.php</code> and so you must proceed as follows, so that the Basic Theme remains intact.</p>
<p>You only have to copy <code>header.php</code>, which is containing the <code>head</code> section of the Theme, into your own Child Theme and here it can be edited as you like. From now on WordPress pulls <code>header.php</code> and not the original file from the basic theme Twenty Ten.</p>
<p>Now you can integrate the mentioned function into the title, an example:</p>
<pre lang="php">
&lt;title&gt;&lt;?php
    /*
     * Print the &lt;title&gt; tag based on what is being viewed.
     * We filter the output of wp_title() a bit -- see
     * twentyten_filter_wp_title() in functions.php.
     */
    if ( function_exists(&#039;seo_title_tag&#039;) )
        seo_title_tag();
    else
        wp_title( &#039;|&#039;, true, &#039;right&#039; );

    ?&gt;&lt;/title&gt;
</pre>
<p>The Basic Theme remains untouched, it can still be kept up to date via updates and from now on WordPress uses the <code>header.php</code> always of the Child Theme.</p>
<p>Like this small example you can replace any template and adapt to your own requirements. Nevertheless, you should bear in mind that you replace the template completely - in the example, we would not notice an update of <code>header.php</code>. So it may be helpful to use Hooks in various areas and have their own functions, more about this later.</p>
<p><strong> Important: </ strong> an exception is <code>functions.php</code>, I will talk more about it later.</strong></p>
<h4>Expand Templates</h4>
<p>In order to meet your own requirements, it may be that you need new templates, template files didn't exist in the Basic Theme. For the purposes of the hierarchy you can extended forever. For example, Twenty Ten does not have <code>home.php</code> - you can simply place this file in your Child Theme and WordPress will use this file, if the state <code> is_home()</code> is true.</p>
<p>Using WordPress 3.0 there is another option outside of the template hierarchy to use your own templates - <a href="http://wpengineer.com/use-more-flexibility-in-wordpress-templates/"><code>get_template_part()</code></a>.</p>
<p>This function is used consistently within Twenty Ten - so you don't have to create own templates for the complete call, but only for the section of the Loop.<br />
For example, Twenty Ten uses for displaying the category archives the call <code>get_template_part( 'loop', 'category' );</code>. Thus it is possible to put a template in our Child Theme, which uses this loop. So it's only necessary to create a file <code>loop-category.php</code> and then save all necessary informations.</p>
<p>In the following example, I adjust the loop, if you are in one of the four categories. Other changes are possible, so you will have full control and flexibility.</p>
<pre lang="php">
if ( in_category( array(47, 37, 27, 45) ) ) {
	query_posts( &#039;cat=&#039;.$cat.&#039;&amp;posts_per_page=-1&amp;orderby=title&amp;order=ASC&#039; );
}	else {
	query_posts( &#039;cat=&#039;.$cat.&#039;&amp;posts_per_page=20&amp;paged=&#039;.$paged );
}
while ( have_posts() ) : the_post(); ?&gt;
</pre>
<p>Similarly, you might be able to customize the loop for <code>index.php</code> - Template file <code>loop-index.php</code> would be in the game.</p>
<h4>Include Functions</h4>
<p>Of course you can also bring in the Child Theme your own functions. If you put an own <code>functions.php</code> in your Child Theme, then it does not replace the <code>functions.php</code> of the Basic Theme!<br />
The functions of the Basic Theme will always be used. You have to disable them via the Hook. The possibility is also explained in a documentation in the functions.php file.</p>
<pre lang="php">
add_action( &#039;after_setup_theme&#039;, &#039;my_child_theme_setup&#039; );
function my_child_theme_setup() {
		// We are providing our own filter for excerpt_length (or using the unfiltered value)
		remove_filter( &#039;excerpt_length&#039;, &#039;twentyten_excerpt_length&#039; );
		...
}
</pre>
<p>Within the function <code>my_child_theme_setup()</code> you can disable the functions of the Basic Theme and bring in your own functions.</p>
<p>Other features belong into the <code>functions.php</code> of the Child Theme - the Basic Theme always remains untouched. In the following code example I disable the function of the Basic Theme Twenty Ten for the length of the excerpt, and load my own function <code>twentytenjump_excerpt_length()</code> and it includes a Widget.</p>
<pre lang="php">
&lt;?php
function twentytenjump_setup() {

	remove_filter( &#039;excerpt_length&#039;, &#039;twentyten_excerpt_length&#039; );
	add_filter( &#039;excerpt_length&#039;, &#039;twentytenjump_excerpt_length&#039; );

	add_action( &#039;widgets_init&#039;, &#039;register_limited_catagories_widget&#039; );
}
add_action( &#039;after_setup_theme&#039;, &#039;twentytenjump_setup&#039; );

function twentytenjump_excerpt_length( $length ) {
	return 10;
}

class limited_catagories_list_widget extends WP_Widget {

	function limited_catagories_list_widget(){
		$widget_ops = array( &#039;classname&#039; =&gt; __(&#039;Selective categories&#039;), &#039;description&#039; =&gt; __(&#039;Show a list of Categories, with the ability to exclude categories&#039;) );

		$control_ops = array( &#039;id_base&#039; =&gt; &#039;some-cats-widget&#039; );
		$this-&gt;WP_Widget( &#039;some-cats-widget&#039;, __(&#039;Selective Catagories&#039;), $widget_ops, $control_ops );
	}

	function form ( $instance){
		$defaults = array( &#039;title&#039; =&gt; __(&#039;Catagories&#039;), &#039;cats&#039; =&gt; &#039;&#039;, &#039;count&#039; =&gt; 0 );
		$instance = wp_parse_args( (array) $instance, $defaults );
		$count = isset($instance&#091;&#039;count&#039;&#093;) ? (bool) $instance&#091;&#039;count&#039;&#093; :false;
		?&gt;
		&lt;p&gt;
			&lt;label for=&quot;&lt;?php echo $this-&gt;get_field_id( &#039;title&#039; ); ?&gt;&quot;&gt;&lt;?php _e( &#039;Title:&#039; ); ?&gt;&lt;/label&gt;
			&lt;input id=&quot;&lt;?php echo $this-&gt;get_field_id( &#039;title&#039; ); ?&gt;&quot; name=&quot;&lt;?php echo $this-&gt;get_field_name( &#039;title&#039; ); ?&gt;&quot; value=&quot;&lt;?php echo $instance&#091;&#039;title&#039;&#093;; ?&gt;&quot; class=&quot;widefat&quot; /&gt;
		&lt;/p&gt;
		&lt;p&gt;
			&lt;input type=&quot;checkbox&quot; class=&quot;checkbox&quot; id=&quot;&lt;?php echo $this-&gt;get_field_id(&#039;count&#039;); ?&gt;&quot; name=&quot;&lt;?php echo $this-&gt;get_field_name(&#039;count&#039;); ?&gt;&quot;&lt;?php checked( $count ); ?&gt; /&gt;
			&lt;label for=&quot;&lt;?php echo $this-&gt;get_field_id(&#039;count&#039;); ?&gt;&quot;&gt;&lt;?php _e( &#039;Show post counts&#039; ); ?&gt;&lt;/label&gt;&lt;br /&gt;
		&lt;/p&gt;
		&lt;p&gt;
			&lt;label for=&quot;&lt;?php echo $this-&gt;get_field_id( &#039;cats&#039; ); ?&gt;&quot;&gt;&lt;?php _e( &#039;Categories to exclude (comma separated list of Category-IDs): &#039; ); ?&gt;&lt;/label&gt;
			&lt;input id=&quot;&lt;?php echo $this-&gt;get_field_id( &#039;cats&#039; ); ?&gt;&quot; name=&quot;&lt;?php echo $this-&gt;get_field_name( &#039;cats&#039; ); ?&gt;&quot; value=&quot;&lt;?php echo $instance&#091;&#039;cats&#039;&#093;; ?&gt;&quot; class=&quot;widefat&quot; /&gt;
		&lt;/p&gt;
		&lt;?php
	}

	function update($new_instance, $old_instance) {
			$instance = $old_instance;
			$instance&#091;&#039;title&#039;&#093; = strip_tags( $new_instance&#091;&#039;title&#039;&#093; );
			$instance&#091;&#039;count&#039;&#093; = !empty($new_instance&#091;&#039;count&#039;&#093;) ? 1 : 0;
			$instance&#091;&#039;cats&#039;&#093;  = strip_tags( $new_instance&#091;&#039;cats&#039;&#093; );
			return $instance;
	}

	function widget($args, $instance){
		extract( $args );
		$title = apply_filters(&#039;widget_title&#039;, $instance&#091;&#039;title&#039;&#093; );
		$c     = $instance&#091;&#039;count&#039;&#093; ? &#039;1&#039; : &#039;0&#039;;
		$cats  = $instance&#091;&#039;cats&#039;&#093;;
		echo $before_widget;
		if ( $title )
			echo $before_title . $title . $after_title;
		echo &#039;&lt;ul&gt;&#039;;
		wp_list_categories(&quot;exclude=$cats&amp;title_li=&amp;show_count=$c&quot;);
		echo &#039;&lt;/ul&gt;&#039;;
		echo $after_widget;
	}

}

function register_limited_catagories_widget(){
	register_widget(&#039;limited_catagories_list_widget&#039;);
}
?&gt;
</pre>
<h3>Conclusion</h3>
<p>I think through the introduction of the new default theme Twenty Ten that some new cool features were added. But I think also that Twenty Ten is very inappropriate to understand the work of WordPress in the area of themes. Especially beginners and PHP newcomers are having a hard time. Yet it creates new opportunities and if you want to use Child Themes in a clean way, then you can not get around it without understanding Hooks in the WordPress API. WordPress takes the idea of the Hooks consistently further, always popular in Plugins, they do get popular in Themes now. Everything has advantages and disadvantages.</p>
<p>But if you use a well-maintained Theme or Framework, then you will appreciate the new possibilities and can always update with no problems. Crucial will be your own knowledge about WordPress - depending on the interest, knowledge and working methods how you create your own themes.</p>
<h3>Download and Forking</h3>
<p>Please use the repository on Github: <a href="https://github.com/bueltge/TwentyTenJump">github.com/bueltge/TwentyTenJump</a><br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2045/understand-wordpress-child-theme/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>List All Subcategories</title>
		<link>http://wpengineer.com/2025/list-all-subcategories/</link>
		<comments>http://wpengineer.com/2025/list-all-subcategories/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 09:42:30 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[categories]]></category>
		<category><![CDATA[list]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[subcategories]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2025</guid>
		<description><![CDATA[Sometimes you just need a list of all child categories only and nothing else. The requirements of projects can be very diverse, as the solution can, and in my case it is a small code snippet that takes care of the output of Subcategories. Something for you to play, improve and expand. Enjoy! $echo = [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes you just need a list of all child categories only and nothing else. The requirements of projects can be very diverse, as the solution can, and in my case it is a small code snippet that takes care of the output of Subcategories. Something for you to play, improve and expand. Enjoy!<br />
<span id="more-2025"></span></p>
<pre lang="php">
$echo = &#039;&lt;ul&gt;&#039; . &quot;\n&quot;;
$childcats = get_categories(&#039;child_of=&#039; . $cat . &#039;&amp;hide_empty=1&#039;);
foreach ($childcats as $childcat) {
    if (1 == $childcat-&gt;category_parent) {
        $echo .= &quot;\t&quot; . &#039;&lt;li&gt;&lt;a href=&quot;&#039; . get_category_link($childcat-&gt;cat_ID).&#039;&quot; title=&quot;&#039; . $childcat-&gt;category_description . &#039;&quot;&gt;&#039;;
        $echo .= $childcat-&gt;cat_name . &#039;&lt;/a&gt;&#039;;
        $echo .= &#039;&lt;/li&gt;&#039; . &quot;\n&quot;;
    }
}
$echo .= &#039;&lt;/ul&gt;&#039; . &quot;\n&quot;;
echo $echo;
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2025/list-all-subcategories/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Use More Flexibility In WordPress Templates</title>
		<link>http://wpengineer.com/2020/use-more-flexibility-in-wordpress-templates/</link>
		<comments>http://wpengineer.com/2020/use-more-flexibility-in-wordpress-templates/#comments</comments>
		<pubDate>Thu, 06 May 2010 11:33:37 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP3.0]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2020</guid>
		<description><![CDATA[Those who have wanted to create their Theme for WordPress quite flexible, and loves the modularization, had always to involve the path to the template. With WordPress 3.0, this will be different and it is possible to use a function, which makes it easy to load the template. An example Let us imagine that you [...]]]></description>
			<content:encoded><![CDATA[<p>Those who have wanted to create their Theme for WordPress quite flexible, and loves the modularization, had always to involve the path to the template. With WordPress 3.0, this will be different and it is possible to use a function, which makes it easy to load the template.</p>
<p><span id="more-2020"></span></p>
<h4>An example</h4>
<p>Let us imagine that you will use a menu several times  - but at different positions and at different places of the markup. It would not be sufficient if you change the appearance via CSS. In most cases you would probably put the navigation in an additional template, such as the <code>nav.php</code>. In this file is the HTML markup and the necessary template tags to create a navigation. This file would be included. In WordPress 3.0 it looks like this: <code>include( TEMPLATEPATH . '/navi.php' );</code></p>
<h4>Function <code>get_template_part()</code></h4>
<p>With WordPress 3.0 comes in this form of modularization more flexibility and so you can use the <code>get_template_part()</code> to address templates. The function allows the use of two parameters:</p>
<pre lang="php">
/**
 * @uses locate_template()
 * @since 3.0.0
 * @uses do_action() Calls &#039;get_template_part{$slug}&#039; action.
 *
 * @param string $slug The slug name for the generic template.
 * @param string $name The name of the specialised template.
 */
get_template_part( $slug, $name = null )
</pre>
<p>and it has a hook <code>get_template_part_$slug</code>, which you can use.</p>
<p>Let's take a look on the example with the navigation above, which will be include in the new function as follows: <code>get_template_part( 'navi' );</code>. In this case we only used the parameter <code>slug</code> - <code>navi</code> - which takes care, that it loads <code>navi.php</code>.<br />
In our next step we want to use the navi, which was created explicitly for the sidebar. The source is in the <code>navi-sidebar.php</code> and the call will look like that: <code>get_template_part( 'navi', 'sidebar' );</code>. The structure of the template file must be created by <code><em>slug</em>-<em>name</em>.php</code> .</p>
<p>This allows to create almost any pattern, which are becoming especially valuable when it comes to reuse, or if you work with Child-Themes, as you can thus connect to the Parent-Theme and yet create your own quite flexible templates.</p>
<h4>Sequence loading</h4>
<p>WordPress uses when loading the template a hierarchy, so you can access various templates, that can be illustrate in an example. The Parent-Theme is in <code>wp-content/themes/</code> and uses the folder <code>wpbasis</code>, the Child Theme can be found in the folder <code>wpbasischild</code>. Now there is in one of the templates the call <code>&lt;?php get_template_part( 'navi', 'index' ); ?&gt;</code>. Now it searches after the <code>navi-index.php</code> with the following pattern:</p>
<ol>
<li>wp-content/themes/wpbasischild/navi-index.php</li>
<li>wp-content/themes/wpbasischild/navi.php</li>
<li>wp-content/themes/wpbasis/navi-index.php</li>
<li>wp-content/themes/wpbasis/navi.php</li>
</ol>
<p>Here, again, some new features under the hood, which can be quite useful for theme authors. Because of its recent growth, the use of Child-Themes is certainly a useful feature.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2020/use-more-flexibility-in-wordpress-templates/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Shortlinks with WordPress 3.0</title>
		<link>http://wpengineer.com/2002/shortlinks-with-wordpress-3-0/</link>
		<comments>http://wpengineer.com/2002/shortlinks-with-wordpress-3-0/#comments</comments>
		<pubDate>Thu, 22 Apr 2010 05:52:10 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress News]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP3.0]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2002</guid>
		<description><![CDATA[There will be a new function in the coming 3.0 version, which will create a shortlink to a post. At default it will be in the header of your frontend. A shortlink would always be with ?p= syntax and the ID of the post. &#60;link rel='shortlink' href='http://bueltge.de/?p=717' /&#62; To use the shortlink in your theme, [...]]]></description>
			<content:encoded><![CDATA[<p>There will be a new function in the coming 3.0 version, which will create a shortlink to a post. At default it will be in the header of your frontend.<br />
<span id="more-2002"></span><br />
A shortlink would always be with <code>?p=</code> syntax and the ID of the post.<br />
<code>&lt;link rel='shortlink' href='http://bueltge.de/?p=717' /&gt;</code></p>
<p><a href="http://wpengineer.com/wp-content/uploads/get_shortlink.png"><img src="http://wpengineer.com/wp-content/uploads/get_shortlink-600x283.png" alt="" title="get_shortlink" width="600" height="283" class="aligncenter size-large wp-image-2003" /></a></p>
<p>To use the shortlink in your theme, you can use a template tag with 4 parameters.</p>
<pre lang="php">
 * @param string $text Optional The link text or HTML to be displayed.  Defaults to &#039;This is the short link.&#039;
 * @param string $title Optional The tooltip for the link.  Must be sanitized.  Defaults to the sanitized post title.
 * @param string $before Optional HTML to display before the link.
 * @param string $before Optional HTML to display after the link.
 */
the_shortlink($text = &#039;&#039;, $title = &#039;&#039;, $before = &#039;&#039;, $after = &#039;&#039;)
</pre>
<p>Here an example how you can use it in your theme:</p>
<pre lang="php">if ( function_exists(&#039;the_shortlink&#039;) ) the_shortlink( __(&#039;Shortlink&#039;), __(&#039;kurze URL zu diesem Beitrag nutzen&#039;), &#039; &middot; &#039; );</pre>
<p>The function <code>wp_get_shortlink()</code> is in use in this case. You should use this function if you don't want to have it displayed (<code>echo</code>).</p>
<p>The link in the head of the frontend is created via a hook and can only get disabled. The integration will be standard in WordPress 3.0:</p>
<pre lang="php">add_action( &#039;wp_head&#039;, &#039;wp_shortlink_wp_head&#039;, 10, 0 );</pre>
<p>To deactivate the syntax in the head of your template you can put the following code in your <code>functions.php</code>.</p>
<pre lang="php">remove_action( &#039;wp_head&#039;, &#039;wp_shortlink_wp_head&#039;, 10, 0 );</pre>
<p>If you like to adjust the shortlink to your liking, you can use several filter hooks.<br />
<code>pre_get_shortlink</code> // Allow plugins to short-circuit this function<br />
<code>get_shortlink</code> // Filter the output<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/2002/shortlinks-with-wordpress-3-0/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Display Always All Subpages in Sidebar</title>
		<link>http://wpengineer.com/1942/display-always-subpages-in-sidebar/</link>
		<comments>http://wpengineer.com/1942/display-always-subpages-in-sidebar/#comments</comments>
		<pubDate>Mon, 04 Jan 2010 07:09:01 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[sidebar]]></category>
		<category><![CDATA[subpages]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1942</guid>
		<description><![CDATA[We hope you had a great start in 2010 and some relaxing holidays the last couple days. Our first post in 2010 is about displaying subpages in a sidebar. Anyone who uses WordPress for company websites, has mostly to do with static pages that are in an hierarchical tree. To access these pages for the [...]]]></description>
			<content:encoded><![CDATA[<p>
We hope you had a great start in 2010 and some relaxing holidays the last couple days. Our first post in 2010 is about displaying subpages in a sidebar. Anyone who uses WordPress for company websites, has mostly to do with static pages that are in an hierarchical tree. To access these pages for the user, there are many possibilities.</p>
<p>In this article I want to show an example in which are the main pages in a horizontal navigation. The related sub-pages are displayed in the sidebar when you click on the main page.</p>
<p><span id="more-1942"></span></p>
<p>For better understanding we take the following page structure:</p>
<ul>
<li>Home</li>
<li>Software
<ul>
<li>Image Editor
<ul>
<li>Adobe Photoshop</li>
<li>Gimp</li>
</ul>
</li>
<li>Content Managment Systems
<ul>
<li>WordPress</li>
<li>Drupal</li>
<li>Joomla</li>
</ul>
</li>
</ul>
</li>
<li>Hardware</li>
<li>About us</li>
</ul>
<p>The pages Home, Software, Hardware and About us are in the horizontal navigation. When the user clicks on Software, for example, all the subpages of Software should be shown in the sidebar.</p>
<p>WordPress provides for such a task the template tag <strong>wp_list_pages()</strong> with several parameters. Since we don't want to display all pages, only the parameter <strong>child_of</strong> is interesting for our purpose. The parameter <strong>child_of</strong> followed by an ID lists all subpages of the current page, if there exist subpages.</p>
<pre lang="php">
&lt;?php wp_list_pages(&#039;child_of=&#039;.get_the_ID().&#039;&amp;title_li=&lt;h5&gt;&#039;.__(&#039;Pages&#039;).&#039;&lt;/h5&gt;&#039;); ?&gt;
</pre>
<p>Now we come to the real problem. If you click on Content Management Systems in the sidebar, only the pages WordPress, Drupal and Joomla will be displayed. The Parent Pages are gone. Logically, since it displays only the children of the current page, which is Content Management Systems. But we always like to have to top page displayed too. Fortunately there is a function <strong>get_post_ancestors</strong>, which returns all parent pages in an array. Try the following:</p>
<pre lang="php">
&lt;?php
$my_page = get_the_ID();
$anchestors = get_post_ancestors($my_page);
var_dump($anchestors);

// click on Software
array(0) { }

// click on Content Management Systems
array(1) { &#091;0&#093;=&gt;  string(2) &quot;63&quot; }
// 63 is the ID of Software

// click on WordPress
array(2) { &#091;0&#093;=&gt;  string(2) &quot;65&quot; &#091;1&#093;=&gt;  string(2) &quot;63&quot; }
// 65 iis the ID of WordPress
?&gt;
</pre>
<p>This would go on forever, even in more deeply nested hierarchy. Important for us are 2 things: the top page is always at the end of the array and it can return an empty array. So we just go to the end of the array and for the case that there is no parent page, we display all the subpages of this page. We write a function in our <code>functions.php</code> because it is easier to maintain, and may also be used in several sidebars:</p>
<pre lang="php">
function wpe_highest_ancestor(){
    global $post;

    $ancestors = array($post-&gt;ancestors);
    $page_ancestors = end( $ancestors );
    if ( !empty($page_ancestors) ) {
        $child_of = $page_ancestors;
    } else {
        $child_of = $post-&gt;ID;
    }

    return $child_of;
}
</pre>
<p>Now we use this function in our sidebar:</p>
<pre lang="php">
&lt;ul class=&quot;sidebar&quot;&gt;
  &lt;?php wp_list_pages(&#039;child_of=&#039; . wpe_highest_ancestor()); ?&gt;
&lt;/ul&gt;
</pre>
<p>If you want to have the name of the top-level page in the sidebar, you can use the following code:</p>
<pre lang="php">
&lt;ul class=&quot;sidebar&quot;&gt;
  &lt;?php
  $child_of = wpe_highest_ancestor();
  wp_list_pages(&#039;child_of=&#039;.$child_of.&#039;&amp;title_li=&lt;h5&gt;&#039;.esc_attr(get_the_title($child_of)).&#039;&lt;/h5&gt;&#039;);
  ?&gt;
&lt;/ul&gt;
</pre>
<p>As you can see, it is relatively easy to achieve appropriate solutions with WordPress.</p>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1942/display-always-subpages-in-sidebar/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>About WordPress Post Thumbnail</title>
		<link>http://wpengineer.com/1925/about-wordpress-post-thumbnail/</link>
		<comments>http://wpengineer.com/1925/about-wordpress-post-thumbnail/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 07:03:45 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Post Thumbnail]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1925</guid>
		<description><![CDATA[This is a complement to our previous post The Ultimative Guide For the_post_thumbnail In WordPress 2.9. In WordPress Version 2.9 probably the most discussed feature is the post thumbnail. Important for this function, it is only working when it is explicitly enabled in the theme. This can be done with the following little snippet in [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-22.jpg" alt="" title="WordPress-Christmas-22" width="600" height="400" class="aligncenter size-full wp-image-1900" />This is a complement to our previous post <a href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/">The Ultimative Guide For the_post_thumbnail In WordPress 2.9</a>. In WordPress <a href="http://codex.wordpress.org/Version_2.9">Version 2.9</a> probably the most discussed feature is the post thumbnail. Important for this function, it is only working when it is explicitly enabled in the theme. This can be done with the following little snippet in the functions.php of the theme: <code>add_theme_support('post-thumbnails');</code>.</p>
<p>But even with this feature you should check for the existence of the function and offer an alternative. Only then you can leave the user the freedom to choose which WordPress version he wants to use. The functions of extensions, plugins and themes should be checked for their existence, then the functionality of the theme is secured, even if a function is not available. Similarly should it be handled with post thumbnail.</p>
<p>I would like to show two suggestions for alternatives below, and I refer to the detailed article about the topic images in <a href="http://wpengineer.com/easier-better-solutions-to-get-pictures-on-your-posts/">Easier And Better Solutions To Get Pictures On Your Posts</a>.</p>
<p><span id="more-1925"></span></p>
<p>After adding the following syntax in the <code>functions.php</code> of the themes, you have a Metabox in the posting or page area ready and can easily be used.</p>
<pre lang="php">
if ( function_exists(&#039;add_theme_support&#039;) )
  add_theme_support(&#039;post-thumbnails&#039;);
</pre>
<p>The output of the image is in the theme at the spot where it should appear, simply use the template tag: <code>the_post_thumbnail()</code>.</p>
<pre lang="php">
if ( current_theme_supports( &#039;post-thumbnails&#039; ) )
  the_post_thumbnail(array(300,200));
</pre>
<p>Important, if you work with additional markup, then you need a query, which checks, whether there is a thumbnail for the post. Otherwise, you have unnecessary markup, which has no content.</p>
<pre lang="php">
&lt;?php
if ( has_post_thumbnail() ) { ?&gt;
  &lt;span class=&quot;my_image&quot;&gt;
    &lt;?php the_post_thumbnail(array(600, 400)); ?&gt;
  &lt;/span&gt;
} ?&gt;
</pre>
<p>To have an alternative for installations prior to WP 2.9, you can take different approaches. The two following examples are providing just ideas: either using the custom fields, field name is <code>post-image</code> ...</p>
<pre lang="php">
if ( function_exists(&#039;has_post_thumbnail&#039;) &amp;&amp; has_post_thumbnail() ) {
  the_post_thumbnail(); // @param: array(height, width)
} else {
  $myimage = get_post_meta($post-&gt;ID, &#039;post-image&#039;, true); // via custom field
  if ($myimage) {
    echo &#039;&lt;img class=&quot;wp-post-image&quot; src=&quot;&#039; . $postimage . &#039;&quot; alt=&quot;Post Iage&quot; /&gt;&#039;;
  }
}
</pre>
<p>... or in the example below, the first image from the photo library. You can find more about it <a href="http://wpengineer.com/easier-better-solutions-to-get-pictures-on-your-posts/">in a separate post</a>.</p>
<pre lang="php">
if ( function_exists(&#039;has_post_thumbnail&#039;) &amp;&amp; has_post_thumbnail() ) {
  the_post_thumbnail(); // @param: array(height, width)
} else {
  // via mediathek
  $attachments = get_children( array(
                  &#039;post_parent&#039;    =&gt; get_the_ID(),
                  &#039;post_type&#039;      =&gt; &#039;attachment&#039;,
                  &#039;numberposts&#039;    =&gt; 1, // show all -1
                  &#039;post_status&#039;    =&gt; &#039;inherit&#039;,
                  &#039;post_mime_type&#039; =&gt; &#039;image&#039;,
                  &#039;order&#039;          =&gt; &#039;ASC&#039;,
                  &#039;orderby&#039;        =&gt; &#039;menu_order ASC&#039;
                  ) );
  foreach ( $attachments as $attachment_id =&gt; $attachment ) {
    echo wp_get_attachment_image( $attachment_id );
  }
}
</pre>
<p><strong>Check</strong> if the theme support the function:</p>
<pre lang="php">
if ( current_theme_supports( &#039;post-thumbnails&#039; ) ) {
  ...
</pre>
<p>In addition, you can check whether the theme supports the function and explicit use for posts (post) or pages (page). Very interesting, if you want to bring additional features in the post edit section of the back end, which is dependent on this feature within the theme:</p>
<pre lang="php">
if ( current_theme_supports( &#039;post-thumbnails&#039;, &#039;page&#039; ) ) {
  add_meta_box( ...
</pre>
<p>In this context, you can also integrate external files with new features.</p>
<pre lang="php">
require_if_theme_supports( &#039;post-thumbnails&#039;, ABSPATH . WPINC . &#039;/my-post-thumbnail-function.php&#039; );
</pre>
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1925/about-wordpress-post-thumbnail/feed/</wfw:commentRss>
		<slash:comments>23</slash:comments>
		</item>
		<item>
		<title>The Ultimative Guide For the_post_thumbnail In WordPress 2.9</title>
		<link>http://wpengineer.com/1930/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/</link>
		<comments>http://wpengineer.com/1930/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 06:50:48 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[template tag]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[wp2.9]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1930</guid>
		<description><![CDATA[WordPress 2.9 RC1 is released and the new post thumbnail function will not change until the final version hopefully. I was chatting a little bit with Sergej Müller last night and we were trying some things out. We found out the following things: Edit: Some little changes, see Matt's comment. You can provide 4 picture [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-18.jpg" alt="WordPress-Christmas-18" title="WordPress-Christmas-18" width="600" height="400" class="aligncenter size-full wp-image-1896" />WordPress 2.9 RC1 is released and the new post thumbnail function will not change until the final version hopefully.<br />
I was chatting a little bit with <a title="wpSEO WordPress SEO Plugin" href="http://wpseo.org">Sergej Müller</a> last night and we were trying some things out. We found out the following things:<br />
<span id="more-1930"></span><br />
<strong>Edit:</strong> Some little changes, see <a href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/#comment-3053">Matt's comment</a>.</p>
<p>You can provide 4 picture formats to the function (change the width and height values to your need):</p>
<pre lang="php">
// the thumbnail
the_post_thumbnail(array(100,100)); 

// medium resolution
the_post_thumbnail(array(300,200));

// large resolution
the_post_thumbnail(array(600, 400));

// original
the_post_thumbnail();
</pre>
<p>You can set how the images should align. It is also possible to assign an own class:</p>
<pre lang="php">
//  left align
the_post_thumbnail(array(100,100), array(&#039;class&#039; =&gt; &#039;alignleft&#039;));

//  right align
the_post_thumbnail(array(100,100), array(&#039;class&#039; =&gt; &#039;alignright&#039;));

//  center
the_post_thumbnail(array(100,100), array(&#039;class&#039; =&gt; &#039;aligncenter&#039;));

// align right and the class  &#039;my_own_class&#039;
the_post_thumbnail(array(100,100), array(&#039;class&#039; =&gt; &#039;alignright my_own_class&#039;));
</pre>
<p>The 3rd possibility is the control of the images size with an array of height and width:<br />
For this purpose we suppose that the settings for thumbnail is 150x150, for medium 300x200 and for large 600x400.</p>
<pre lang="php">
// thumbnail scaled to 60x60 pixel
the_post_thumbnail(array(60,60), array(&#039;class&#039; =&gt; &#039;alignleft&#039;)); 

// original thumbnail
the_post_thumbnail(array(150,150), array(&#039;class&#039; =&gt; &#039;alignleft&#039;));

// medium resolution scaled to 200x133 pixel
the_post_thumbnail(array(200,200), array(&#039;class&#039; =&gt; &#039;alignleft&#039;));

// large resolution scaled to 400x266 Pixel
the_post_thumbnail(array(400,345), array(&#039;class&#039; =&gt; &#039;alignleft&#039;));
</pre>
<p>We see that the image proportions are always maintained, even if one specifies crooked values.</p>
<p>For the Theme Designers is this not necessarily easier, because no one knows what the user will put in his settings o his library. One way to approach this problem, to query the options for the various sizes:</p>
<pre lang="php">
// width of the thumbnails
get_option(&#039;thumbnail_size_w&#039;);

//  height of the thumbnails
get_option(&#039;thumbnail_size_h&#039;);

//  height of the medium resolution
get_option(&#039;medium_size_h&#039;);

//  width of the large resolution
get_option(&#039;large_size_w&#039;);

//  1 = Crop thumbnail to exact dimensions, 0 = Crop off
get_option(&#039;thumbnail_crop&#039;)
</pre>
<p>You can change these values in your theme.</p>
<pre lang="php">
$w = get_option(&#039;thumbnail_size_w&#039;) / 2;
$h = get_option(&#039;thumbnail_size_h&#039;) /2;

the_post_thumbnail(array($w, $h), array(&#039;class&#039; =&gt; &#039;alignleft&#039;));
</pre>
<p>Here another example: If the size of a thumbnail is bigger than 100x100 and crop is activated, then the thumbnail should be resized to 100x100, otherwise use the original thumbnail.</p>
<pre lang="php">
if(get_option(&#039;thumbnail_size_w&#039;) &gt; 100 &amp;&amp; get_option(&#039;thumbnail_crop&#039;) == 1) {
    the_post_thumbnail(array(100,100));
}else{
    the_post_thumbnail(&#039;thumbnail&#039;);
}
</pre>
<p>Have fun with post thumbnails! But be aware, that each post thumbnail requires 2 data base queries. On a page with 10 posts that would be 20 more queries.<br />
<hr /><a href="http://wpplugins.com/plugin/281/snippets" title="More informations about this plugin for WordPress"><img src="http://wpengineer.com/wp-content/themes/wpe-3/images/snippets-125-125.png" height="90" alt="WordPress Snippet Plugin" /></a> <a href="http://xtreme-theme.com"><img src="http://wpengineer.com/wp-content/uploads/feed-banner-2.jpg" alt="Xtreme One WordPress Framework"/></a><br />
&copy; <a href="http://wpengineer.com/">WP Engineer Team</a>, All rights reserved <small>(Digital Fingerprint: WPEngineer-be0254ce2b4972feb4b9cb72034a092d)</small></p>
]]></content:encoded>
			<wfw:commentRss>http://wpengineer.com/1930/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/feed/</wfw:commentRss>
		<slash:comments>107</slash:comments>
		</item>
	</channel>
</rss>

