<?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; WordPress Themes</title>
	<atom:link href="http://wpengineer.com/tag/wordpress-themes/feed/" rel="self" type="application/rss+xml" />
	<link>http://wpengineer.com</link>
	<description>WordPress News, Hacks, Tips, Tutorials, Plugins and Themes</description>
	<lastBuildDate>Mon, 21 May 2012 22:48:48 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Enqueue comment-reply.js &#8211; The Right Way</title>
		<link>http://wpengineer.com/2358/enqueue-comment-reply-js-the-right-way/</link>
		<comments>http://wpengineer.com/2358/enqueue-comment-reply-js-the-right-way/#comments</comments>
		<pubDate>Thu, 15 Dec 2011 14:15:14 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[TwentyEleven]]></category>
		<category><![CDATA[WordPress]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2358</guid>
		<description><![CDATA[Since Google takes the loading time of a page as a ranking factor, it is always important for a theme designer to incorporate the required resources correctly. In Xtreme One WordPress Framework our JavaScripts are loaded only when they are really needed. Do you have a slider widget on the home page, then the JavaScript [...]]]></description>
			<content:encoded><![CDATA[<p>Since Google takes the loading time of a page as a ranking factor, it is always important for a theme designer to incorporate the required resources correctly. In <a title="Xtreme One Professional WordPress Framework" href="http://xtreme-theme.com">Xtreme One WordPress Framework</a> our JavaScripts are loaded only when they are really needed. Do you have a slider widget on the home page, then the JavaScript for the slider included only on the homepage.</p>
<p>Also including <code>comment-reply.js</code> can be optimized. In the Theme TwentyEleven we can find it in <code>header.php</code> (Line 58):</p>
<pre>if ( is_singular() &amp;&amp; get_option( &#039;thread_comments&#039; ) )
	wp_enqueue_script( &#039;comment-reply&#039; );</pre>
<p>That means, if "Enable threaded (nested) comments" in the Discussion Settings is activated and if it's on a single page, then load the script <code>comments-reply.js</code>.<br />
But we also don't need the script on pages where there is no comment form and not on the homepage if it's a page. Neither do we need the script if comments are closed or not allowed.<br />
Or easier to say: <strong>We only need it, if "Enable threaded comments" is activated and a comment form is displayed.</strong></p>
<p>Using the example of TwentyEleven I show now how to do it better. First, we delete from the <code>header.php</code> the lines</p>
<pre>if ( is_singular() &amp;&amp; get_option( &#039;thread_comments&#039; ) )
	wp_enqueue_script( &#039;comment-reply&#039; );</pre>
<p>In the <code>functions.php</code> we implement the enqueue function of the script</p>
<pre>function xtreme_enqueue_comments_reply() {
	if( get_option( &#039;thread_comments&#039; ) )  {
		wp_enqueue_script( &#039;comment-reply&#039; );
	}
}</pre>
<p>Now we get to the important part. We add to the function <code>twentyeleven_setup()</code> this line:</p>
<pre>add_action( &#039;comment_form_before&#039;, &#039;xtreme_enqueue_comments_reply&#039; );</pre>
<p>The Hook <code>comment_form_before</code> is only there when the comment form is loaded and we are adding the enqueue function for the script. A positive side effect, the script is now loaded at the end of the document and does not hinder the loading of the site.<br />
At best, you create a Child Theme, so the changes are protected against overwriting when you update WordPress the next time. Maybe the WordPress Dev team will use this approach in a future version of their default Theme TwentyEleven.<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/2358/enqueue-comment-reply-js-the-right-way/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Win 5 Licenses Of The New WordPress Framework Xtreme One Version &#8211; Including Awesome New Features!</title>
		<link>http://wpengineer.com/2268/wordpress-framework-xtreme-one-version-1-3/</link>
		<comments>http://wpengineer.com/2268/wordpress-framework-xtreme-one-version-1-3/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 18:59:40 +0000</pubDate>
		<dc:creator>Alex</dc:creator>
				<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[Premium Themes]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Framework]]></category>
		<category><![CDATA[Xtreme One]]></category>
		<category><![CDATA[Xtreme Theme]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2268</guid>
		<description><![CDATA[With version 1.3 many features were added to improve the workflow and significantly improve page performance. An overview of all the special features of Xtreme Theme can be seen here: Besides many small changes under the hood, the new Widget System Extensions is one of the biggest innovation in Xtreme One. For multisite installations widgets [...]]]></description>
			<content:encoded><![CDATA[<p>With <a href="http://xtreme-theme.com/xtreme-one/">version 1.3</a> many features were added to improve the workflow and significantly improve page performance. An overview of all the special features of Xtreme Theme can be seen here:</p>
<p><iframe src="http://player.vimeo.com/video/29110129?title=0&amp;byline=0&amp;portrait=0" width="440" height="248" frameborder="0" webkitAllowFullScreen allowFullScreen></iframe></p>
<p>Besides many small changes under the hood, the new Widget System Extensions is one of the biggest innovation in Xtreme One.</p>
<ul>
<li>For multisite installations widgets can be declared as a side wide widgets, which means they appear on all existing and future blogs.</li>
<li>Widget Manager to manage various features as well as turning on or off the widgets.</li>
<li> Extremely comfortable widget filtering logic, see video: <a href="http://xtreme-theme.com/video/different-sliders-for-different-categories/" title="WordPress Framework Features">Different sliders for different categories</a> including conditional editor with drag and drop and syntax check.</li>
<li> Quick duplication of widgets for multiple use.</li>
<li>Simple combining multiple widgets to a tabber, see video: <a href="http://xtreme-theme.com/video/create-a-tabber-with-widgets/">Create a tabber from widgets</a>.</li>
<li>Scripts will only load when they are needed.</li>
</ul>
<p>Also new are the jFancy Mediaslider and a Carousel Slider, which are available for posts and as a media slider. With the media slider you can just insert images from your media library instead of choosing an image of a post. You can link these images either to the attachment page, the corresponding article or a user defined link. </p>
<p>The Xtreme Social Widget added the new Google+.</p>
<p>Another feature are the <a href="http://xtreme-theme.com/video/post-subtitles-in-xtreme-one-1-3/">subtitles for posts</a>, pages and custom post format.</p>
<p>Xtreme One Framework supports post formats. Thus it is possible with any Childtheme, to operate a Tumblr-like blog.</p>
<p>The selectable positions of the navigation has been increased to 12.</p>
<p>Xtreme One costs only $79,95 and is available <a href="http://xtreme-theme.com/xtreme-one/">here</a>.</p>
<h3>How can you win a license?</h3>
<p>We are giving away 5 licenses for the Xtreme One Framework with a Childtheme of your choice. One license will be given away among the commentators in our comment area. 2 more will be raffled among those who tweet with the Hashtag #xtremeonewpe about Xtreme One and two licenses will be raffled among all the bloggers who write about Xtreme One in their blog and leave a trackback here. The raffle will run until September 23rd 2011, 23:59:59 PST Time. </p>
<p>The winner will be announced on September 24th at the end of our Xtreme One session at the WordCamp Germany in Cologne.</p>
<p>Good Luck to everyone!</p>
<p><strong>We just announced the <a href="http://wpengineer.com/2275/winner-of-xtreme-one-wordpress-framework-2/">winner of the licenses here</a>:</strong></p>
<p>Congrats to the winner!</p>
<p>Everybody else can grab a 20% discount for Xtreme One until October 3rd 2011 with the coupon code: WCK11</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/2268/wordpress-framework-xtreme-one-version-1-3/feed/</wfw:commentRss>
		<slash:comments>70</slash:comments>
		</item>
		<item>
		<title>Launching WordPress Framework Xtreme One!</title>
		<link>http://wpengineer.com/2092/new-wordpress-framework-xtreme-one-online/</link>
		<comments>http://wpengineer.com/2092/new-wordpress-framework-xtreme-one-online/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 09:25:35 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress News]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Childhthemes]]></category>
		<category><![CDATA[WordPress Framework]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2092</guid>
		<description><![CDATA[We are very happy and proud to announce the international launch of Xtreme One WordPress Framework today. After a very successful one month pre-launch in Germany we are excited to offer Xtreme One for only $79,95 worldwide now. Xtreme One was programmed by Heiko and I, Alex is responsible for the design. Why another WordPress [...]]]></description>
			<content:encoded><![CDATA[<p><img class="size-medium wp-image-2094 alignleft" title="WordPress-Christmas-2010-06" src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-2010-061-300x200.jpg" alt="" width="300" height="200" />We are very happy and proud to announce the <a title="International Launch of Xtreme One" href="http://xtreme-theme.com/2010/12/release-xtreme-one-wordpress-framework/">international launch</a> of <a title="Xtreme One Professional WordPress Framework" href="http://xtreme-theme.com">Xtreme One WordPress Framework</a> today. After a very successful one month pre-launch in Germany we are excited to offer <a title="Xtreme One Features" href="http://xtreme-theme.com/xtreme-one/">Xtreme One</a> for <strong>only $79,95</strong> worldwide now. <a title="Xtreme One Features" href="http://xtreme-theme.com/xtreme-one/">Xtreme One</a> was programmed by Heiko and I, Alex is responsible for the design.</p>
<h3>Why another WordPress Framework?</h3>
<p>My idea of a WordPress Framework starts where most of the others are given up - to give the user the complete control of his layout. That's why Xtreme One is worldwide the only WordPress Framework, which is able to create fixed, fluid and flexible layouts. Create in a matter of minutes your own desired website layout with just a few mouse clicks! Check out the video and get convinced by Xtreme One.</p>
<p><iframe src="http://player.vimeo.com/video/16499282" width="599" height="337" frameborder="0"></iframe></p>
<h3>Focus on the most important thing – your vision!</h3>
<p>Efficient functions enables you to work extremely fast, without writing code. Hence, you have more time to create your design.</p>
<h3>It's the details that matter</h3>
<ul>
<li>6 layout variations in content area.</li>
<li>Widths of sidebars flexible adjustable in px, em or %</li>
<li>Free positionable navigations with 4 different stylesheets for WP Menus, page or categories</li>
<li>Able to add teaser and footer with dynamical created widget areas in 28 layout variations and up to 5 columns.</li>
<li>Layoutmanager  - different layouts and sidebars</li>
<li>12 additional widgets: 3 slider widgets, 5 widgets for column and row based output of your articles and pages, printable and accessible tabber, last tweets, newsletter and social links.</li>
<li>3 comment form layouts, additional text fields, adjustable avatar size and alignment</li>
<li>Combining of stylesheets and stylesheet compression.</li>
<li>Multisite and Localization ready, in English and German.</li>
<li>Extensive <a title="Xtreme One Documentation" href="http://documentation.xtreme-theme.com">documentation</a>, <a title="Xtreme Theme Support Forum" href="http://support.xtreme-theme.com">support forum</a>, <a title="Xtreme Theme Knowledge Base" href="http://knowledgebase.xtreme-theme.com">knowledgebase</a>, free updates</li>
<li>and a lot more</li>
</ul>
<h3>Launch rebate until December 13th</h3>
<p>To celebrate the launch of Xtreme One Framework, we will give you a $10 rebate until December 13th. Just type in LAUNCH  in the Discount Coupon field when you check out.</p>
<div class="buybuttons"><a class="button teaserbuy float_left" href="https://secure.avangate.com/order/checkout.php?PRODS=4529460&amp;QTY=1&amp;CART=2"><span class="buy">Buy Xtreme One</span></a></div>
<h3>And that's only the beginning!</h3>
<p>In the coming months, we will come up with many more innovative ideas for <a title="Xtreme One Professional WordPress Framework" href="http://xtreme-theme.com/xtreme-one/">Xtreme One</a> and we will try to make Xtreme One the best WordPress Framework out there. I know it's tough goal, but we will try to deliver!</p>
<p>Buy it now for a limited time for $69,95 and receive free updates with even more features in the future. We hope you will enjoy Xtreme One!</p>
<p>We are looking forward to hear your feedback!<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/2092/new-wordpress-framework-xtreme-one-online/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Flattr Button for WordPress without a Plugin</title>
		<link>http://wpengineer.com/2022/flattr-button-4-wordpress-without-a-plugin/</link>
		<comments>http://wpengineer.com/2022/flattr-button-4-wordpress-without-a-plugin/#comments</comments>
		<pubDate>Thu, 10 Jun 2010 08:15:45 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Plugin]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=2022</guid>
		<description><![CDATA[There is a lot talking about Flattr and the idea certainly is worth a try. That's why I wanted to test and integrate Flattr in our blog. However, I don't really like the Plugin and that's why I created a small little function, which integrates the button as you can see right under the tweets [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/flattr-logo-beta.png" alt="" title="flattr-logo-beta" width="218" height="43" class="alignright size-full wp-image-2023" /><br />
There is a lot talking about <a href="http://flattr.com/">Flattr</a> and the idea certainly is worth a try. That's why I wanted to test and integrate Flattr in our blog. However, I don't really like the Plugin and that's why I created a small little function, which integrates the button as you can see right under the tweets of each post.<br />
<span id="more-2022"></span></p>
<h4>The function</h4>
<p>The following small function goes in the <code>functions.php</code> of the themes or outsourced in a Plugin. It depends what is your opinion - for me it is theme-specific and thus a function of the theme and therefore in the <code>functions.php</code> of the theme.</p>
<pre lang="php">
/**
 * Flattr Button in WordPress Templates
 *
 * @author Frank Bültge
 * @link   Flattr API https://flattr.com/support/api
 * @param  integer  $uid   personal user ID
 * @param  string   $cat   Flattr category: text, images, video, audio, software or rest.
 * @param  string   $btn   Type of Flattr button: &#039;&#039; or &#039;compact&#039;
 * @param  integer  $hide  Use this to hide the thing from listings on flattr.com. The value 1 will hide the thing.
 *
 */
function fb_flattr_link($uid = &#039;&#039;, $cat = &#039;text&#039;, $btn = &#039;compact&#039;, $hide = 0) {

	$uid  = (int) $uid;
	$cat  = htmlspecialchars($cat);
	$btn  = htmlspecialchars($btn);
	$hide = (int) $hide;

	$noflattr = 0;
	$noflattr = (int) get_post_meta( get_the_ID(), &#039;noflattr&#039;, true );

	if ( !$uid )
		$uid = (int) get_post_meta( get_the_ID(), &#039;flattrid&#039;, true );

	if ( defined(&#039;WPLANG&#039;) )
		$locale = WPLANG;
	if ( empty($locale) )
		$locale = &#039;en_US&#039;;

	$ftag = &#039;&#039;;
	$tags = get_the_tags( get_the_ID() );
	if ( $tags ) {
		foreach( $tags as $tag ) {
			$ftag .= $tag-&gt;name . &#039;, &#039;;
		}
		$ftag = substr( $ftag, 0, -2 );
	} else {
		$tag = &#039;&#039;;
	}

	$dsc = htmlspecialchars( strip_tags( trim( get_the_excerpt() ) ) );
	$dsc = str_replace( &quot;&#039;&quot;, &quot;&quot;, $dsc );
	$dsc = str_replace( &quot;\n&quot;, &quot; &quot;, $dsc ); // maybe \r\n

	$tle = htmlspecialchars( strip_tags( get_the_title() ) );
	$tle = str_replace( &quot;&#039;&quot;, &quot;&quot;, $tle );

	$flattr = &#039;
	&lt;span class=&quot;flattr&quot;&gt;
		&lt;script type=&quot;text/javascript&quot;&gt;
			var flattr_uid  = \&#039;&#039; . $uid . &#039;\&#039;;
			var flattr_url  = \&#039;&#039; . get_permalink() . &#039;\&#039;;
			var flattr_tle  = \&#039;&#039; . $tle . &#039;\&#039;;
			var flattr_dsc  = \&#039;&#039; . $dsc . &#039;\&#039;;
			var flattr_cat  = \&#039;&#039; . $cat . &#039;\&#039;;
			var flattr_lng  = \&#039;&#039; . $locale . &#039;\&#039;;
			var flattr_tag  = \&#039;&#039; . $ftag . &#039;\&#039;;
			var flattr_btn  = \&#039;&#039; . $btn . &#039;\&#039;;
			var flattr_hide = &#039; . $hide . &#039;;
		&lt;/script&gt;
		&lt;script src=&quot;http://api.flattr.com/button/load.js&quot; type=&quot;text/javascript&quot;&gt;&lt;/script&gt;
	&lt;/span&gt;
	&#039;;

	if ( !$noflattr &amp;&amp; ( 0 != $uid ) )
		echo $flattr;
}
</pre>
<h4>Usage</h4>
<p>Within the template for your posts the above function will be called, the call would normally be appropriate in the <code>single.php</code> of the theme.</p>
<pre lang="php">
&lt;?php if ( function_exists(&#039;fb_flattr_link&#039;) ) fb_flattr_link( $uid = &#039;YOUR_UID&#039; ); ?&gt;
</pre>
<p>There is a query in this code, which checks a custom field with the name flattrid. There you can put an ID, so you can use the button in dependency of different authors. You can use the above function without the use of the parameter $uid , like this:</p>
<pre lang="php">
&lt;?php if ( function_exists(&#039;fb_flattr_link&#039;) ) fb_flattr_link(); ?&gt;
</pre>
<p>The button will only show if the custom field contains a flattrid and if the following field noflattr is not 1.</p>
<p>I also added a custom field - if you use this just type <code>noflattr</code> and as the value <code>1</code>, then the button won't display. I think there are posts that do not need a flattr button, for example because it is a guest post.</p>
<p><a href="http://wpengineer.com/wp-content/uploads/noflattr.png"><img src="http://wpengineer.com/wp-content/uploads/noflattr-300x104.png" alt="" title="noflattr" width="300" height="104" class="aligncenter size-medium wp-image-2024" /></a></p>
<p>The button will be displayed within the span-element with the class <code>flattr</code> and can be addressed via CSS, here a small example:</p>
<pre lang="css">
.flattr {
margin: 5px 0 0 5px;
}
</pre>
<p>The function can be expanded in many ways, for example a profile field on authors profile page for the ID can help, better as an custom field.</p>
<p>You can also outsource everything in Metaboxes, thus making it more user-friendly and automatically showing it before the content or in your feed. Since Flattr provides its own Plugin, I didn't wanted to build a Plugin and who may use the function can extend it accordingly, if the current functionality is not enough.<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/2022/flattr-button-4-wordpress-without-a-plugin/feed/</wfw:commentRss>
		<slash:comments>7</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>Load A Stylesheet Only If Use Gallery</title>
		<link>http://wpengineer.com/1949/load-a-stylesheet-only-if-use-gallery/</link>
		<comments>http://wpengineer.com/1949/load-a-stylesheet-only-if-use-gallery/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 13:43:34 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[gallery]]></category>
		<category><![CDATA[hack]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1949</guid>
		<description><![CDATA[In relation to the better Gallery it is actually not necessary to load the stylesheet if there is no gallery, so it is worth it to check in advance whether the gallery will be used in the post or not. For this you have to parse the post which can be done in two ways. [...]]]></description>
			<content:encoded><![CDATA[<p>In relation to the <a better href="http://wpengineer.com/a-solution-for-the-wordpress-gallery/">better Gallery </a> it is actually not necessary to load the stylesheet if there is no gallery, so it is worth it to check in advance whether the gallery will be used in the post or not. For this you have to parse the post which can be done in two ways.<br />
<span id="more-1949"></span><br />
The classic solution is to parse the content and seek the short code, classic PHP <a href="http://php.net/manual/en/function.strstr.php"><code>strstr</code></a>. Depending on the result it loads the stylesheet.<br />
<code>if ( strstr( $post->post_content, '[gallery' ) )</code>.<br />
This obviously takes time and performance, what you really like to avoid. Thus, it is better if you can parse the post in advance. In this context, there is a <a href="http://wordpress.org/support/topic/350167#post-1344676">tread in the forum of WordPress</a>, which contains a very nice solution by <a href="http://w-shadow.com/">WhiteShadow</a> which you can use to load the stylesheet.</p>
<pre lang="php">
// onyl css, when post has a gallery
function gallery_stylesheet( $posts ) {
	if ( empty( $posts ) )
		return $posts;

	$found = false;

	foreach ($posts as $post) {
		if ( stripos( $post-&gt;post_content, &#039;&#091;gallery&#039; ) )
			$found = TRUE;
			break;
		}

	if ( $found )
		wp_enqueue_style( &#039;gallery-stylesheet&#039;, get_bloginfo(&#039;stylesheet_directory&#039;) . &#039;/gallery.css&#039;, FALSE, FALSE, &#039;screen&#039; );

	return $posts;
}
add_action( &#039;the_posts&#039;, &#039;gallery_stylesheet&#039; );
</pre>
<p>You can also use this to load scripts,</p>
<pre lang="php">
// onyl js, when post has a gallery
function my_script( $posts ) {
	if ( empty( $posts ) )
		return $posts;

	$found = false;

	foreach ($posts as $post) {
		if ( stripos( $post-&gt;post_content, &#039;&#091;my-script&#039; ) )
			$found = TRUE;
			break;
		}

	if ( $found )
		wp_enqueue_script( &#039;my-script&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/js/my_script.js&#039;, FALSE, FALSE, TRUE );

	return $posts;
}
add_action(&#039;the_posts&#039;, &#039;my_script&#039;);
</pre>
<p>For more information, to include JavaScript and CSS files, there is <a href="http://wpengineer.com/use-javascript-libraries-in-and-of-wordpress/">another post</a> about this topic.<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/1949/load-a-stylesheet-only-if-use-gallery/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Contactable &#8211; Contact Form Easy with WordPress</title>
		<link>http://wpengineer.com/1936/contactable-contaktform-easy-with-wordpress/</link>
		<comments>http://wpengineer.com/1936/contactable-contaktform-easy-with-wordpress/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 11:07:45 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Contact Form]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1936</guid>
		<description><![CDATA[The integration of a contact form in WordPress usually begins with a search of a Plugin and often ends with a great effort too. Since scripts are loaded on all pages and posts - only to be integrated on one side of a form. The blog is only as good as his technician and I [...]]]></description>
			<content:encoded><![CDATA[<p>The integration of a contact form in WordPress usually begins with a search of a Plugin and often ends with a great effort too. Since scripts are loaded on all pages and posts - only to be integrated on one side of a form. The blog is only as good as his technician and I would like to show a very simple way how to integrate a contact form into your own blog without much knowledge.<br />
<span id="more-1936"></span><br />
The solution is not the holy grail, but it shows how easy and resource friendly it is to integrate a contact form in WordPress.<br />
So that we can devote ourselves fully to the integration, and we do not have to deal with PHP and JavaScript, I'll use for the example the great form Plugin <a href="http://theodin.co.uk/blog/ajax/contactable-jquery-plugin.html"><strong>contactable</strong></a> for jQuery by Philip Beel. This Plugin brings all the necessary files and only needs to be integrated - very easy to use and you can adapt to your own needs. Documentation can be found on the <a href="http://theodin.co.uk/blog/ajax/contactable-jquery-plugin.html">Plugin site</a>. For the integration of the form I use the standard Kubrick theme on WordPress, but you can use it in any other theme.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/contactable.png" alt="" title="contactable" width="450" height="316" class="aligncenter size-full wp-image-1937" /></p>
<p>WordPress provides the jQuery library. The calling of all the necessary files and scripts will take place within the template, which takes care to output the contact form. This call we'll do with the functions of WordPress - so we make sure that the files really are loaded only once. WordPress takes care of the correct order and of the dependencies.</p>
<p>First we create a template, I call it <code>contact-page.php</code> and it must be stored in the folder of your themes. This includes calling the necessary scripts and the associated stylesheets. Basically, you only need these four calls to store in the <code>page.php</code> of your theme, assign a new name for the file and put a comment to get recognized by WordPress (at the beginning the file). The following describes the syntax of the example of <code>page.php</code> in the default theme Kubrick.</p>
<pre lang="php">
&lt;?php
/**
 * Template Name: Contact Page
 *
 * @package WordPress
 * @subpackage Default_Theme
 */

wp_enqueue_script( &#039;jquery.contactable&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/contactable/jquery.contactable.js&#039;, array(&#039;jquery&#039;) , 3.1, true );
wp_enqueue_script( &#039;jquery.validate&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/contactable/jquery.validate.pack.js&#039;, array(&#039;jquery&#039;) , 3.1, true );
wp_enqueue_script( &#039;my_contactable&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/contactable/my_contactable.js&#039;, array(&#039;jquery&#039;) , 3.1, true );
wp_enqueue_style( &#039;contactable&#039;, get_bloginfo(&#039;template_directory&#039;) . &#039;/contactable/contactable.css&#039; );

get_header(); ?&gt;

    &lt;div id=&quot;content&quot; class=&quot;narrowcolumn&quot; role=&quot;main&quot;&gt;

        &lt;div class=&quot;post&quot; id=&quot;post-&lt;?php the_ID(); ?&gt;&quot;&gt;
        &lt;h2&gt;&lt;?php the_title(); ?&gt;&lt;/h2&gt;

            &lt;div class=&quot;entry&quot;&gt;
                &lt;?php the_content(&#039;&lt;p class=&quot;serif&quot;&gt;Read the rest of this page &raquo;&lt;/p&gt;&#039;); ?&gt;

                &lt;div id=&quot;mycontactform&quot;&gt; &lt;/div&gt;

            &lt;/div&gt;
        &lt;/div&gt;

    &lt;/div&gt;

&lt;?php get_sidebar(); ?&gt;

&lt;?php get_footer(); ?&gt;
</pre>
<p>As you can see in the syntax, I have saved all files of the jQuery Form Plugnis in the folder <code>contactable</code> in the folder of the theme. Therefore, your paths may have to be adjusted. Right now it looks like this in my theme:</p>
<ul>
<li>
default
<ul>
<li>contactable
<ul>
<li>jquery.contactable.js</li>
<li>jquery.validate.pack.jss</li>
<li>my.contactable.js</li>
<li>contactable.css</li>
</ul>
</li>
<li>style.css</li>
<li>contact-page.php</li>
<li>...</li>
</ul>
</li>
</ul>
<p>I only added the file <code>my.contactable.js</code>; this takes care to call the form and can be filled with parameters. Their content is as follows:</p>
<pre lang="php">
jQuery(document).ready( function($){
    $(&#039;#mycontactform&#039;).contactable({
        name: &#039;Name&#039;,
        email: &#039;E-Mail&#039;,
        message : &#039;Message&#039;,
        recipient: &#039;example@domain.com&#039;,
        subject: &#039;Contact Form&#039;,
        recievedMsg : &#039;Thanks for your message.&#039;
    });
});
</pre>
<p>If all files are stored and are adapted to your needs, then you only need to create a page in the admin area of WordPress. Give the page a name, if you want fill it with content and select a template - in our case the <strong>Contact Page</strong>. After saving the page, you should view it in the front end and click on the small label and the form will appear and can be filled out.</p>
<p>Through the call with the help of WordPress functions and the right parameters, the scripts are now integrated  in the footer of the site. The jQuery library will not be called, it will be added by WordPress if it is not there yet, by the dependence of the parameters for the key <code>jquery</code>. By using a template with all calls, all the scripts and stylesheets are only involved if the page is called by WordPress. If you want the form snippets on all sides, you can insert the call in the <code>header.php</code> or <code>functions.php</code>.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/contactable-ocss.png" alt="" title="contactable-ocss" width="450" height="533" class="aligncenter size-full wp-image-1938" /></p>
<p>You do not want to use this feature, then either don't use that CSS, or add your own design or you can fit the JS to your own needs. The same applies for additional fields in the form, this must be adapted to the content of the files.<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/1936/contactable-contaktform-easy-with-wordpress/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Advent Calendar &#8211; 24 Days Tips And Tricks Each Day! Today: WordPress Comment Form Widget</title>
		<link>http://wpengineer.com/1875/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/</link>
		<comments>http://wpengineer.com/1875/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/#comments</comments>
		<pubDate>Tue, 01 Dec 2009 04:43:41 +0000</pubDate>
		<dc:creator>Michael</dc:creator>
				<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Advent Calendar]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[Widget]]></category>
		<category><![CDATA[Widget API]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Themes]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1875</guid>
		<description><![CDATA[Especially in Germany we have the tradition of an Advent Calendar. An Advent calendar is a special calendar which is used to count down the days from December the 1st to Christmas Eve December 24th. An Advent Calendar has 24 doors, one of which is opened every day during Advent. Each door opens to reveal [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://wpengineer.com/wp-content/uploads/WordPress-Christmas-01.jpg" alt="WordPress-Christmas-01" title="WordPress-Christmas-01" width="600" height="400" class="aligncenter size-full wp-image-1879" /></p>
<p>Especially in Germany we have the tradition of an Advent Calendar. An Advent calendar is a special calendar which is used to count down the days from December the 1st to Christmas Eve December 24th. </p>
<p>An Advent Calendar has 24 doors, one of which is opened every day during Advent. Each door opens to reveal an image, a poem, or part of a story such as the Nativity story itself. More elaborate Advent calendars have a small gift concealed in each door, such as a toy or a chocolate item.</p>
<p>At WP Engineer, we thought we should do the same and open a door every day, which contains a little gift for our readers, by providing them a WordPress tip or trick each day. So we hope you will be exciting to see what tip, hack or news will be behind the door the next morning. Enjoy a new little WordPress gift every day until December 24th. <img src='http://wpengineer.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Our first little gift is a code snippet to implement the commentform as a widget in your sidebar. This Widget only works with WordPress 2.8 and higher since it's using the new <a href="http://wpengineer.com/wordpress-built-a-widget/" title="WordPress Widget API">Widget API</a>. Just paste the code in the functions.php of your theme and drag the Widget on your sidebar.<br />
<span id="more-1875"></span></p>
<pre lang="php">
&lt;?php
class wpe_comment_widget extends WP_Widget {

    function wpe_comment_widget() {
        $widget_ops = array(&#039;classname&#039; =&gt; &#039;wpe_widget_comments&#039;, &#039;description&#039; =&gt; __( &#039;Your comments and commentform&#039;, &#039;your_textdomain&#039;) );
        $this-&gt;WP_Widget(&#039;wpe-comment-widget&#039;, __(&#039;WPE Comments&#039;, &#039;your_textdomain&#039;), $widget_ops);
    }

    function widget($args, $instance) {
        if(is_single()) {
            extract($args);
            global $post;
            echo $before_widget;
            comments_template();
            echo $after_widget;
        }
    }

    function update($new_instance, $old_instance) {
        $instance = $old_instance;
        return $instance;
    }

    function form($instance) {
        ?&gt;
        &lt;p&gt;&lt;?php _e(&#039;This widget will only be displayed in single view.&#039;, &#039;your_textdomain&#039;); ?&gt;&lt;/p&gt;
       &lt;?php
    }
}

register_widget(&#039;wpe_comment_widget&#039;);
?&gt;
</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/1875/advent-calendar-24-days-tips-and-tricks-each-day-today-wordpress-comment-form-widget/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Use WordPress Login</title>
		<link>http://wpengineer.com/1773/use-wordpress-login/</link>
		<comments>http://wpengineer.com/1773/use-wordpress-login/#comments</comments>
		<pubDate>Fri, 06 Nov 2009 10:19:00 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1773</guid>
		<description><![CDATA[WordPress makes it pretty easy to log in and out of WordPress in a theme. Basically with two functions &#60;?php $redirect = &#039;wp-admin/post-new.php&#039;; if ( !is_user_logged_in() ) { $link = &#039;&#60;a href=&#34;&#039; . esc_url( wp_login_url( $redirect ) ) . &#039;&#34;&#62;&#039; . __(&#039;Login&#039;) . &#039;&#60;/a&#62;&#039;; } else { $link = &#039;&#60;a href=&#34;&#039; . esc_url( wp_logout_url( $redirect [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress makes it pretty easy to log in and out of WordPress in a theme. Basically with two functions<br />
<span id="more-1773"></span></p>
<pre lang="php">
&lt;?php
$redirect = &#039;wp-admin/post-new.php&#039;;
if ( !is_user_logged_in() ) {
    $link = &#039;&lt;a href=&quot;&#039; . esc_url( wp_login_url( $redirect ) ) . &#039;&quot;&gt;&#039; . __(&#039;Login&#039;) . &#039;&lt;/a&gt;&#039;;
} else {
    $link = &#039;&lt;a href=&quot;&#039; . esc_url( wp_logout_url( $redirect ) ) . &#039;&quot;&gt;&#039; . __(&#039;Logout&#039;) . &#039;&lt;/a&gt;&#039;;
}
echo $link; // or echo apply_filters(&#039;loginout&#039;, $link);
?&gt;
</pre>
<p>But I'm not going into details - in this article I would like to go a little further and show how, for example, the login form gets into the theme. Thus adjustments to the design and integration to your own needs can be implemented very easily.<br />
<!--more--><br />
In the first example I want to show you the classic login form so its not too much code. The following syntax shows a simple login form in your theme. I have not made any further adjustments and used the default login form of WordPress.</p>
<pre lang="php">
&lt;form action=&quot;&lt;?php echo wp_login_url(get_permalink()); ?&gt;&quot; method=&quot;post&quot;&gt;
	&lt;label for=&quot;log&quot;&gt;
		&lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;log&quot; value=&quot;&lt;?php echo wp_specialchars(stripslashes($user_login), 1) ?&gt;&quot; size=&quot;22&quot; /&gt; User
	&lt;/label&gt;&lt;br /&gt;
	&lt;label for=&quot;pwd&quot;&gt;
		&lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;pwd&quot; size=&quot;22&quot; /&gt; Password
	&lt;/label&gt;&lt;br /&gt;
	&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;Send&quot; class=&quot;button&quot; /&gt;
	&lt;label for=&quot;rememberme&quot;&gt;
		&lt;input name=&quot;rememberme&quot; id=&quot;rememberme&quot; type=&quot;checkbox&quot; checked=&quot;checked&quot; value=&quot;forever&quot; /&gt; Remember me
	&lt;/label&gt;
&lt;/form&gt;
&lt;?php } ?&gt;
</pre>
<p>This is not always sufficient and depends on the users who are logged, and whether one can even register on the website, I wrote a little example which pays attention to various aspects.<br />
<a href="http://wpengineer.com/wp-content/uploads/loginform.png"><img src="http://wpengineer.com/wp-content/uploads/loginform.png" alt="loginform" title="loginform" width="217" height="115" class="alignleft size-full wp-image-1774" /></a></p>
<p>The following syntax is the view of logged user (<code> if ($ user_ID) </code>) , which is a completely different to new users, they get the form only if they are allowed to register (<code>get_option('users_can_register')</code>) , depending on the settings in the backend of WordPress.<br />
Similarly, users with a User_Level greater than 1 (<code>if ( $user_level &gt;= 1 )</code>) get one link more to write an article. Alternatively, you can also use the function <code>current_user_can()</code> and therefore explicitly asked for the user role.</p>
<pre lang="php">
&lt;?php
global $user_ID, $user_identity, $user_level;
if ( $user_ID ) { ?&gt;

	&lt;h3&gt;&lt;?php _e( &#039;Control panel&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/h3&gt;
	&lt;ul&gt;
		&lt;li&gt;&lt;?php _e( &#039;Identified as&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt; &lt;strong&gt;&lt;?php echo $user_identity ?&gt;&lt;/strong&gt;.
			&lt;ul&gt;
				&lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo(&#039;url&#039;) ?&gt;/wp-admin/&quot;&gt;&lt;?php _e( &#039;Dashboard&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;&lt;/li&gt;

				&lt;?php if ( $user_level &gt;= 1 ) { ?&gt;
					&lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo(&#039;url&#039;) ?&gt;/wp-admin/post-new.php&quot;&gt;&lt;?php _e( &#039;Write an article&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;?php } ?&gt;

				&lt;li&gt;&lt;a href=&quot;&lt;?php bloginfo(&#039;url&#039;) ?&gt;/wp-admin/profile.php&quot;&gt;&lt;?php _e( &#039;Profile&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;&lt;/li&gt;
				&lt;li&gt;&lt;a href=&quot;&lt;?php esc_url( wp_logout_url( urlencode($_SERVER&#091;&#039;REQUEST_URI&#039;&#093;) ) ); ?&gt;&quot;&gt;&lt;?php _e( &#039;Exit&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;&lt;/li&gt;
			&lt;/ul&gt;
		&lt;/li&gt;
	&lt;/ul&gt;

&lt;?php } elseif ( get_option(&#039;users_can_register&#039;) ) { ?&gt;

		&lt;h3&gt;&lt;?php _e( &#039;Identification&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/h3&gt;
		&lt;ul&gt;
			&lt;li&gt;
				&lt;form action=&quot;&lt;?php echo wp_login_url(get_permalink()); ?&gt;&quot; method=&quot;post&quot;&gt;
					&lt;p&gt;
						&lt;label for=&quot;log&quot;&gt;
							&lt;?php _e( &#039;User&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;
							&lt;input type=&quot;text&quot; name=&quot;log&quot; id=&quot;log&quot; value=&quot;&lt;?php echo wp_specialchars(stripslashes($user_login), 1) ?&gt;&quot; size=&quot;22&quot; /&gt;
						&lt;/label&gt;&lt;br /&gt;
						&lt;label for=&quot;pwd&quot;&gt;
							&lt;?php _e( &#039;Password&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;
							&lt;input type=&quot;password&quot; name=&quot;pwd&quot; id=&quot;pwd&quot; size=&quot;22&quot; /&gt;
						&lt;/label&gt;&lt;br /&gt;
						&lt;input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;&lt;?php _e( &#039;Send&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&quot; class=&quot;button&quot; /&gt;
						&lt;label for=&quot;rememberme&quot;&gt;
							&lt;input name=&quot;rememberme&quot; id=&quot;rememberme&quot; type=&quot;checkbox&quot; checked=&quot;checked&quot; value=&quot;forever&quot; /&gt;&lt;?php _e( &#039;Remember me&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;
						&lt;/label&gt;&lt;br /&gt;
						&lt;input type=&quot;hidden&quot; name=&quot;redirect_to&quot; value=&quot;&lt;?php echo $_SERVER&#091;&#039;REQUEST_URI&#039;&#093;; ?&gt;&quot;/&gt;
					&lt;/p&gt;
				&lt;/form&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href=&quot;&lt;?php echo site_url(&#039;wp-login.php?action=register&#039;, &#039;login&#039;); ?&gt;&quot;&gt;&lt;?php _e( &#039;Register&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;
			&lt;/li&gt;
			&lt;li&gt;
				&lt;a href=&quot;&lt;?php echo site_url(&#039;wp-login.php?action=lostpassword&#039;, &#039;login&#039;);	 ?&gt;&quot;&gt;&lt;?php _e( &#039;Recover password&#039;, FB_BASIS_TEXTDOMAIN ); ?&gt;&lt;/a&gt;
			&lt;/li&gt;
		&lt;/ul&gt;

&lt;?php } ?&gt;
</pre>
<p>If user level is insufficient, you may also extend WordPress, either via code or using a Plugin.<br />
With the help of a few lines of PHP you can assign a role quickly.</p>
<pre lang="php">
function my_new_object() {
	global $wp_roles;

	$wp_roles-&gt;add_cap(&#039;administrator&#039;, &#039;MyObject&#039;);
}

// start an activation theme
if ( is_admin() &amp;&amp; isset($_GET&#091;&#039;activated&#039;&#093; ) &amp;&amp; $pagenow == &#039;themes.php&#039; )
	my_new_object();
</pre>
<p>The object can simply be requested via standard.<br />
<code>if ( current_user_can('MyObject') )</code></p>
<p>Alternatively you can also create new roles: <code>add_role('New_Role', 'New name of the role');</code>. The function also allows the simultaneous use of rights, therefore a third optional parameter is available, which expects several values in an array. Otherwise, the objects can be add via <code>add_cap()</code>.</p>
<p>This is only a small approach, many opportunities arise - have fun with the benefits of these possibilities.<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/1773/use-wordpress-login/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Easier And Better Solutions To Get Pictures On Your Posts</title>
		<link>http://wpengineer.com/1735/easier-better-solutions-to-get-pictures-on-your-posts/</link>
		<comments>http://wpengineer.com/1735/easier-better-solutions-to-get-pictures-on-your-posts/#comments</comments>
		<pubDate>Tue, 20 Oct 2009 11:04:24 +0000</pubDate>
		<dc:creator>Frank</dc:creator>
				<category><![CDATA[WordPress Tutorials]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Themes]]></category>
		<category><![CDATA[WP]]></category>

		<guid isPermaLink="false">http://wpengineer.com/?p=1735</guid>
		<description><![CDATA[WordPress makes it pretty easy to upload picture on posts and pages. Thereby are various data stored, which can be used. Again and again, you can read tutorials on how to bring photos to posts, normally this is a solution via the custom fields. But there is a different and simpler solution, I think. The [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress makes it pretty easy to upload picture on posts and pages. Thereby are various data stored, which can be used.<br />
Again and again, you can read tutorials on how to bring photos to posts, normally this is a solution via the custom fields. But there is a different and simpler solution, I think. The maintenance of custom fields is not always necessary.<br />
Therefore, I would like to show some solutions that are, in my opinion, much better and can be expanded in many ways.</p>
<p><span id="more-1735"></span></p>
<h3>With custom fields</h3>
<p>In the first case, the solution using a custom field to be displayed, while the data must be maintained in this field to a key.</p>
<p>In version 1 you store the value of the authors to the key <code>author link</code>, so it's easy to understand the use of the fields. More information about this can be found in the <a href="http://codex.wordpress.org/Using_Custom_Fields">Codex</a>.</p>
<h4>Version 1</h4>
<p><img src="http://wpengineer.com/wp-content/uploads/wp-cf.png" alt="wp-cf" title="wp-cf" width="450" height="209" class="aligncenter size-full wp-image-1736" /><br />
The output of the key is handed over by using the template tag <code>get_post_meta()</code>. The function expects the Id of the post and the key value as a mandatory, or alternatively you can set if a value or arrays are allowed. Put on <code>true</code> and it returns only a string</p>
<pre lang="php">
/**
 * @param int $post_id Post ID.
 * @param string $key The meta key to retrieve.
 * @param bool $single Whether to return a single value.
 * @return mixed Will be an array if $single is false. Will be value of meta data field if $single
 *  is true.
 */
function get_post_meta($post_id, $key, $single = false)
</pre>
<pre lang="php">
&lt;?php $key = &#039;authorlink&#039;; ?&gt;
&lt;p&gt;Photo of &lt;a href=&quot;&lt;?php echo get_post_meta($post-&gt;ID, $key, true);?&gt;&quot;&gt;&lt;/a&gt;.&lt;/p&gt;
</pre>
<p>The next step is basically no different, except that we now put the address in a value to another key, where the picture is. This requires the author to know address and save the URL.<br />
<img src="http://wpengineer.com/wp-content/uploads/wp-cf2.png" alt="wp-cf2" title="wp-cf2" width="450" height="207" class="aligncenter size-full wp-image-1737" /></p>
<p>In version 2, however, we go one step further and put a function into the <code>functions.php</code>, which takes care of it and then we can feed it with data. Again, this is just an example and needs in this version the key of the custom fields, the width and height of the images. These three sample values, we then write in the tag to output the image.</p>
<h4>Version 2</h4>
<pre lang="php">
/*Custom Field Images*/
function image_attachment($key, $width, $height) {
	global $post;

	$custom_field = get_post_meta($post-&gt;ID, $key, true);
	if ($custom_field) {
		echo &#039;&lt;img src=&quot;&#039; . $custom_field . &#039;&quot; alt=&quot;Post Image&quot; width=&quot;&#039; . $width . &#039;&quot; height=&quot;&#039; . $height . &#039;&quot; /&gt;&#039;;
	} else {
		return;
	}
}
</pre>
<p>The output of the template is determined by the above function as follows.</p>
<pre lang="php">
&lt;?php
$image_key = &#039;image&#039;;
$myimage = get_post_meta($post-&gt;ID, $image_key, true);
if ($myimage) { ?&gt;
	&lt;div class=&quot;post-image&quot;&gt;
		&lt;?php image_attachment($image_key, 512, 200); ?&gt;
	&lt;/div&gt;
&lt;?php } ?&gt;
</pre>
<p>This really can make some beautiful things. Many theme authors would like to just have a picture to a post, which is directly taken at various points. Often this is achieved through the above solution. However, this requires that the authors need to know the custom fields and maintain them, so the key of the custom field and URL to the image.</p>
<p>Not very comfortable, so I want to show a solution, how you can get the image that was uploaded to the post, which can be found in the Gallery of the post.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/wp-images.png" alt="wp-images" title="wp-images" width="450" height="346" class="aligncenter size-full" /></p>
<h3>WordPress own functions for images</h3>
<p>One of the many options is <code>wp_get_attachment_image()</code>, which represents in my view, the simplest solution. Here is an example of what explains it in more detail.</p>
<p>At first we just get all pictures, not all the attachments of the posts that has been uploaded directly to the post. These images, we can directly display. The syntax must always be in the loop.</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(&#039;post_parent&#039; =&gt; get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt; &#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo wp_get_attachment_image($attachment_id);
} ?&gt;
</pre>
<p>The above example loads via the loop all images and display them. We don't take care about the actual size of the image, in default it will display the thumbnail. By setting <code>post_mime_type</code> = <code>image</code>, it only fetches images and not other attachments of the post.<br />
The function of WordPress, which outputs the image with HTML, requieres the ID of the attachment, so you have to retrieve the ID to the post beforehand, we'll do with <code>get_children()</code>.</p>
<p>A few words now to function <code>wp_get_attachment_image()</code> of WP to display the images. As already mentioned, there are several functions that all have a similar structure, and either give back other markup or allow other parameters. For a simple output, this function is best. It is also described in the <a href="http://codex.wordpress.org/Function_Reference/wp_get_attachment_image"> Codex</a>.</p>
<p>The function allows for 3 parameters:</p>
<pre lang="php">
/**
 * Get an HTML img element representing an image attachment
 *
 * @param int $attachment_id Image attachment ID.
 * @param string $size Optional, default is &#039;thumbnail&#039;.
 * @param bool $icon Optional, default is false. Whether it is an icon.
 * @return string HTML img element or empty string on failure.
 */
function wp_get_attachment_image($attachment_id, $size = &#039;thumbnail&#039;, $icon = false)
</pre>
<p>You get the markup back for the img-Tag, like the following example.</p>
<pre lang="php">
&lt;mg width=&quot;150&quot; height=&quot;150&quot; src=&quot;http://example.com/wp-content/uploads/2009/08/DSC00261-150x150.jpg&quot;; class=&quot;attachment-thumbnail2 alt=&quot;Image Example&quot; title=&quot;Example Image&quot; /&gt;
</pre>
<p>The last of the three parameters is not really interesting in association with pictures, since it displays an icon. But the second parameter is there even more exciting, because this allows to set the size of the image. Here you can give either one of the preconfigured sizes, the sizes which you can configure in the settings of WordPress and are created when you upload using the media library. The following options are available.</p>
<ul>
<li>Default-Values: <code>thumbnail</code>, <code>medium</code>, <code>large</code> oder <code>full</code></li>
<li>Custom sizes via Array: array( width, height ) Example: <code>array(100, 100)</code></li>
</ul>
<p>If you pass your own values, then WordPress fetches the appropriate image in dependence of these values. So if you set, for example, 100x100 and the thumbnails are 150px150px, then these images are drawn. If you have your own array of 200x200, it will output the medium image because the thumbnail is too small.</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(&#039;post_parent&#039; =&gt; get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt;&#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo wp_get_attachment_image( $attachment_id, array(200, 250) );
} ?&gt;
</pre>
<h4>Images with links</h4>
<p>Now I will not always just the pictures, but also have the image with a link to the image in original size. In that case there is the function <code>wp_get_attachment_link()</code>. Here an example:</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(&#039;post_parent&#039; =&gt; get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt;&#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo wp_get_attachment_link( $attachment_id, &#039;medium&#039; );
} ?&gt;
</pre>
<p>The HTML looks like this.</p>
<pre lang="php">
&lt;a href=&quot;http://example.com/wp-content/uploads/2009/08/DSC00261.JPG&quot; title=&quot;Example Image&quot;&gt;&lt;img src=&quot;http://example.com/wp-content/uploads/2009/08/DSC00261-150x150.jpg&quot; class=&quot;attachment-thumbnail&quot; alt=&quot;Image Example&quot; title=&quot;Example Image&quot; height=&quot;150&quot; width=&quot;150&quot;/&gt;&lt;/a&gt;
</pre>
<p>Thus the image in the requested size is generated, and the link was set to the image in original size.</p>
<h3>Determine size of the images</h3>
<p>Sometimes you want to know in advance how big is the image. There is a function that returns the values as an array. This is an example of the output:</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(&#039;post_parent&#039; =&gt; get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt; &#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	$src = wp_get_attachment_image_src( $attachment_id, &#039;full&#039; );
	var_dump($src);
} ?&gt;
</pre>
<p>This simple loop to output the values returns an array.</p>
<pre lang="php">
array
  0 =&gt; string &#039;http://example.com/wp-content/uploads/2009/08/DSC00261.JPG&#039; (length=63)
  1 =&gt; int 1632
  2 =&gt; int 1224
  3 =&gt; boolean false
</pre>
<p>The order of the array is allocated as follows.</p>
<ul>
<li>$src[0] => url</li>
<li>$src[1] => width</li>
<li>$src[2] => height</li>
<li>$src[3] => icon</li>
</ul>
<p>Thus, it can react to the size, depending on requirements. Alternatively, you can work with the function <code>image_get_intermediate_size($post_id, $size='thumbnail')</code>, which returns some more values. A sample of the output for 'medium':</p>
<pre lang="php">
array
  &#039;file&#039; =&gt; string &#039;DSC00261-300x225.jpg&#039; (length=20)
  &#039;width&#039; =&gt; string &#039;300&#039; (length=3)
  &#039;height&#039; =&gt; string &#039;225&#039; (length=3)
  &#039;path&#039; =&gt; string &#039;2009/08/example-300x225.jpg&#039; (length=28)
  &#039;url&#039; =&gt; string &#039;http://example.com/wp-content/uploads/2009/08/DSC00261-300x225.jpg&#039; (length=71)
</pre>
<h3>Further functions and possibilities</h3>
<p>In this context, there are a few other functions that enable the work with attachments or pictures. I do not want to explain each of them, therefore I constribute a small loop for testing purposes. This covers many possibilities and are self explanatory, I think.</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(&#039;post_parent&#039; =&gt; get_the_ID(), &#039;post_type&#039; =&gt; &#039;attachment&#039;, &#039;post_mime_type&#039; =&gt; &#039;image&#039;) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo &#039;&lt;p&gt;&#039;;
	echo &#039;wp_get_attachment_image: &#039; . wp_get_attachment_image( $attachment_id, array(200,250) ) . &#039;&lt;br /&gt;&#039;;
	echo &#039;wp_get_attachment_link: &#039; . wp_get_attachment_link( $attachment_id ) . &#039;&lt;br /&gt;&#039;;
	echo &#039;wp_get_attachment_url: &#039; . wp_get_attachment_url( $attachment_id ) . &#039;&lt;br /&gt;&#039;;
	echo &#039;wp_get_attachment_thumb_url: &#039; . wp_get_attachment_thumb_url( $attachment_id ) . &#039;&lt;br /&gt;&#039;;
	echo &#039;get_attachment_link: &#039; . get_attachment_link( $attachment_id ) . &#039;&lt;br /&gt;&#039;;
	$src = image_get_intermediate_size( $attachment_id, &#039;medium&#039;	 );
	echo &#039;image_get_intermediate_size. &#039;; var_dump($src); echo &#039;&lt;br /&gt;&#039;;
	$src = wp_get_attachment_image_src( $attachment_id, &#039;full&#039;, true );
	echo &#039;wp_get_attachment_image_src. &#039;; var_dump($src); echo &#039;&lt;br /&gt;&#039;;
	echo &#039;Title of attachment: &#039; . apply_filters( &#039;the_title&#039;, $attachment-&gt;post_title ) . &#039;&lt;br /&gt;&#039;;
	echo &#039;Link to post: &#039; . get_permalink($image-&gt;post_parent) . &#039;&lt;br /&gt;&#039;;
	echo &#039;&lt;hr style=&quot;clear:both;&quot; /&gt;&lt;/p&gt;&#039;;
} ?&gt;
</pre>
<p>Remember, the syntax must be in the loop of WordPress.</p>
<h4>Only one picture to post</h4>
<p>Now I have explained how to get the pictures but in general you will probably not need to post all the pictures, but you want just one picture. This occurs, for example, in magazine themes, where a small picture is displayed to make the post more interesting. Through these functions I can give the author of the respective post the control of that picture. Normally I do this in such a way that it explicitly output the first picture from the gallery to the post. Thus, the author can move the image in the gallery by dragging and dropping to the right place.</p>
<p><img src="http://wpengineer.com/wp-content/uploads/wp-gallery-reihenfolge.png" alt="wp-gallery-reihenfolge" title="wp-gallery-reihenfolge" width="450" height="375" class="aligncenter size-full wp-image-1739" /></p>
<p>This is not an own function, you just have to feed <code>get_children()</code> accordingly. The output of the image, and other values to the image is again as described above.</p>
<p>In our first example we pick <strong>only the first image</strong> from the gallery.</p>
<pre lang="php">
&lt;?php
$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 );
} ?&amp;&gt;
</pre>
<p>Now the author of the contribution can always choose the first image of what he wants to use.</p>
<p>Alternatively we can turn the tables and get the <strong> last image from the Gallery </strong>.</p>
<pre lang="php">
&lt;?php
$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;DESC&#039;,
				&#039;orderby&#039;        =&gt;&#039;menu_order ASC&#039;
				) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo wp_get_attachment_image( $attachment_id );
} ?&gt;
</pre>
<p>With the help of numberposts, we specify how many images are to be fetched. So we fetch in the following example the <strong>first 2 pics</strong> and after the <strong>last 2 pictures</strong>.</p>
<pre lang="php">
&lt;?php
$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 );
} ?&gt;
</pre>
<p>Well, the <strong>last two pictures</strong>, starting with the last picture.</p>
<pre lang="php">
&lt;?php
$attachments = get_children( array(
				&#039;post_parent&#039;    =&gt; get_the_ID(),
				&#039;post_type&#039;      =&gt; &#039;attachment&#039;,
				&#039;numberposts&#039;    =&gt; 2, // 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;DESC&#039;,
				&#039;orderby&#039;        =&gt; &#039;menu_order ASC&#039;
				) );
foreach ( $attachments as $attachment_id =&gt; $attachment ) {
	echo wp_get_attachment_image( $attachment_id );
} ?&gt;
</pre>
<h3>Meta-Data of images</h3>
<p>WordPress saves various meta data to the images. Now and then these are very useful, and why not simply use them.</p>
<p>First an example to get to the data. This we do with the function <code>wp_get_attachment_metadata()</code>. This function returns quite a lot of data and we can access the size of images, their path and also access the meta data.</p>
<pre lang="php">
&lt;?php
$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 );
	$imagemeta = wp_get_attachment_metadata( $attachment_id );
	var_dump($imagemeta); // list values in array

	$aperture          = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;aperture&#039;&#093;;
	$credit            = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;credit&#039;&#093;;
	$camera            = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;camera&#039;&#093;;
	$caption           = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;caption&#039;&#093;;
	$created_timestamp = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;created_timestamp&#039;&#093;;
	$copyright         = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;copyright&#039;&#093;;
	$focal_length      = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;focal_length&#039;&#093;;
	$iso               = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;iso&#039;&#093;;
	$shutter_speed     = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;shutter_speed&#039;&#093;;
	$title             = $imagemeta&#091;&#039;image_meta&#039;&#093;&#091;&#039;title&#039;&#093;;
} ?&gt;
</pre>
<p>In the above code is the output value of a <code>var_dump()</code> in it. Thus we see very quickly which content in the array exists and where they can be accessed.<br />
All values of the meta data, I have written in each variable, so that even less experienced users should understand it.</p>
<p>For a simple picture, of what would be created via cell phone camera, for example, the array looks like this.</p>
<pre lang="php">
array
  &#039;width&#039; =&gt; string &#039;1632&#039; (length=4)
  &#039;height&#039; =&gt; string &#039;1224&#039; (length=4)
  &#039;hwstring_small&#039; =&gt; string &#039;height=&#039;96&#039; width=&#039;128&#039;&#039; (length=23)
  &#039;file&#039; =&gt; string &#039;2009/08/DSC00261.JPG&#039; (length=20)
  &#039;sizes&#039; =&gt;
    array
      &#039;thumbnail&#039; =&gt;
        array
          &#039;file&#039; =&gt; string &#039;DSC00261-150x150.jpg&#039; (length=20)
          &#039;width&#039; =&gt; string &#039;150&#039; (length=3)
          &#039;height&#039; =&gt; string &#039;150&#039; (length=3)
      &#039;medium&#039; =&gt;
        array
          &#039;file&#039; =&gt; string &#039;DSC00261-300x225.jpg&#039; (length=20)
          &#039;width&#039; =&gt; string &#039;300&#039; (length=3)
          &#039;height&#039; =&gt; string &#039;225&#039; (length=3)
      &#039;large&#039; =&gt;
        array
          &#039;file&#039; =&gt; string &#039;DSC00261-1024x768.jpg&#039; (length=21)
          &#039;width&#039; =&gt; string &#039;1024&#039; (length=4)
          &#039;height&#039; =&gt; string &#039;768&#039; (length=3)
  &#039;image_meta&#039; =&gt;
    array
      &#039;aperture&#039; =&gt; string &#039;2.8&#039; (length=3)
      &#039;credit&#039; =&gt; string &#039;&#039; (length=0)
      &#039;camera&#039; =&gt; string &#039;W800i&#039; (length=5)
      &#039;caption&#039; =&gt; string &#039;&#039; (length=0)
      &#039;created_timestamp&#039; =&gt; string &#039;1184253323&#039; (length=10)
      &#039;copyright&#039; =&gt; string &#039;&#039; (length=0)
      &#039;focal_length&#039; =&gt; string &#039;0&#039; (length=1)
      &#039;iso&#039; =&gt; string &#039;100&#039; (length=3)
      &#039;shutter_speed&#039; =&gt; string &#039;0.0166666666667&#039; (length=15)
      &#039;title&#039; =&gt; string &#039;&#039; (length=0)
</pre>
<h3>Alternative in WordPress 2.9</h3>
<p>Using WordPress version 2.9, there is a template tag just for this request, so it is easier and more understandable. You just use the <code>the_post_image()</code> and you can set the size. Default is <code>thumbnail</code>, it is possible <code>thumbnail</code>, <code>medium</code>, <code>large</code> or <code>full</code>.</p>
<pre lang="php">
the_post_image(); // without parameter -&gt; Thumbnail
the_post_image(&#039;thumbnail&#039;); // Thumbnail
the_post_image(&#039;medium&#039;); // Medium resolution - use full,
</pre>
<p>As a small alternative is still <code>get_the_post_image()</code> available, whereas the function doesn't have echo, and can optionally have the ID of the post.<br />
<code>get_the_post_image( $size = 'thumbnail', $post_id = NULL )</code></p>
<h3>Conclusion</h3>
<p>WordPress offers a lot of different functions to access attachments, whether pictures or other files. Also a part of meta-data is stored, which can be used. Many approaches can be found in the code, primarily in the <code>wp-includes/media.php</code>. Perhaps I could point out some solutions which in my view a better alternative than the use of custom fields, or even scanning the content.<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/1735/easier-better-solutions-to-get-pictures-on-your-posts/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>

