<?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>Digging into WordPress &#187; tags</title>
	<atom:link href="http://digwp.com/tag/tags/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 18 May 2012 18:21:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Rounded Font-Sizes (with Colors!) for Tag Clouds</title>
		<link>http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/</link>
		<comments>http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 15:09:11 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[tag-cloud]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1316</guid>
		<description><![CDATA[Tag clouds accomplish their varied font sizes by applying inline styling to each tag. The resulting font sizes can be really weird like style='font-size:29.3947354754px;'. There is nothing inherently wrong about that, but it feels a bit unsettling and less controllable. Mike Summers sent in a solution he uses on his own site. Let&#8217;s check it [...]]]></description>
			<content:encoded><![CDATA[<p>Tag clouds accomplish their varied font sizes by applying inline styling to each tag. The resulting font sizes can be really weird like <tt>style='font-size:29.3947354754px;'</tt>. There is nothing inherently wrong about that, but it feels a bit unsettling and less controllable. <a href="http://oldguygaming.com/">Mike Summers</a> sent in a solution he uses on his own site. Let&#8217;s check it out.</p>
<p><span id="more-1316"></span></p>
<pre><code>&lt;div id="tagCloud"&gt;
  &lt;ul&gt;
    &lt;?php
      $arr = wp_tag_cloud(array(
        'smallest'   =&gt; 8,          // font size for the least used tag
        'largest'    =&gt; 40,         // font size for the most used tag
        'unit'       =&gt; 'px',       // font sizing choice (pt, em, px, etc)
        'number'     =&gt; 200,        // maximum number of tags to show
        'format'     =&gt; 'array',    // flat, list, or array. flat = spaces between; list = in li tags; array = does not echo results, returns array
        'separator'  =&gt; '',         //
        'orderby'    =&gt; 'name',     // name = alphabetical by name; count = by popularity
        'order'      =&gt; 'RAND',     // starting from A, or starting from highest count
        'exclude'    =&gt; '',         // ID's of tags to exclude, displays all except these
        'include'    =&gt; '',         // ID's of tags to include, displays none except these
        'link'       =&gt; 'view',     // view = links to tag view; edit = link to edit tag
        'taxonomy'   =&gt; 'post_tag', // post_tag, link_category, category - create tag clouds of any of these things
        'echo'       =&gt; true        // set to false to return an array, not echo it
      ));
      foreach ($arr as $value) {
        $ptr1 = strpos($value,'font-size:');
        $ptr2 = strpos($value,'px');
        $px = round(substr($value,$ptr1+10,$ptr2-$ptr1-10));
        $value = substr($value, 0, $ptr1+10) . $px . substr($value, $ptr2);
        $ptr1 = strpos($value, "class=");
        $value = substr($value, 0, $ptr1+7) . 'color-' . $px . ' ' . substr($value, $ptr1+7);
        echo '&lt;li&gt;' . $value . '&lt;/li&gt; ';
      }
    ?&gt;
  &lt;/ul&gt;
&lt;/div&gt;</code></pre>
<p>The result turns this:</p>
<pre><code>&lt;a href='url' class='tag-link-66' title='6 topics' style='font-size:29.3947354754px;'&gt;Tag Name&lt;/a&gt;</code></pre>
<p>into this:</p>
<pre><code>&lt;a href='url' class='color-29 tag-link-66' title='6 topics' style='font-size:29px;'&gt;Tag Name&lt;/a&gt;</code></pre>
<h3>Class names for colors</h3>
<p>Notice in the above output that the link has a class name of &#8220;color-29&#8243; now that it didn&#8217;t before. Now you have a hook to colorize tag names based on their size.</p>
<pre><code>.color-29 {
   color: red;
}</code></pre>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/">Permalink</a> | <a href="http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/#comments">7 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/&title=Rounded Font-Sizes (with Colors!) for Tag Clouds">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/tag-cloud/" rel="tag">tag-cloud</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/01/rounded-font-sizes-tag-clouds/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>The Difference Between is_singular() and is_single()</title>
		<link>http://digwp.com/2009/10/difference-between-is_singular-and-is_single/</link>
		<comments>http://digwp.com/2009/10/difference-between-is_singular-and-is_single/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 06:56:58 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[tips]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=836</guid>
		<description><![CDATA[You know that you can target single-view pages with the conditional tag, is_single(): &#60;?php if(is_single()) { // do something } else { // do something else } ?&#62; This is a great way to conditionally apply styles, scripts, and markup to single-view pages. But did you know about the conditional tag, is_singular()? The is_singular() tag [...]]]></description>
			<content:encoded><![CDATA[<p>You know that you can target single-view pages with the conditional tag, <code>is_single()</code>:</p>
<pre><code>&lt;?php
if(is_single()) {

	// do something

} else {

	// do something else

}
?&gt;</code></pre>
<p>This is a great way to conditionally apply styles, scripts, and markup to single-view pages. </p>
<p>But did you know about the conditional tag, <code>is_singular()</code>? The <code>is_singular()</code> tag enables you to target single-view pages, regular page pages, and attachment pages all in one fell swoop.</p>
<p><span id="more-836"></span></p>
<p>So, instead of writing something like this:</p>
<pre><code>&lt;?php
if(is_single() || is_page() || is_attachment()) {

	// do something

} else {

	// do something else

}
?&gt;</code></pre>
<p>We can write this instead:</p>
<pre><code>&lt;?php
if(is_singular()) {

	// do something

} else {

	// do something else

}
?&gt;</code></pre>
<p>The <code>is_singular()</code> tag is what&rsquo;s known as a &ldquo;boolean&rdquo; function, meaning that it returns one of two values, either <code>TRUE</code> or <code>FALSE</code>. No parameters are associated with this tag.</p>
<p>Now you know :)</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/10/difference-between-is_singular-and-is_single/">Permalink</a> | <a href="http://digwp.com/2009/10/difference-between-is_singular-and-is_single/#comments">3 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/10/difference-between-is_singular-and-is_single/&title=The Difference Between is_singular() and is_single()">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/tags/" rel="tag">tags</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/10/difference-between-is_singular-and-is_single/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Definitive Guide to WordPress Page Navigation</title>
		<link>http://digwp.com/2009/08/wordpress-page-navigation/</link>
		<comments>http://digwp.com/2009/08/wordpress-page-navigation/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 05:03:47 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=560</guid>
		<description><![CDATA[There are many ways to navigate a WordPress-powered site. There are archive links, category links, page links, internal post links, single post links, admin comment links, tag links, and many other types of navigational links. When it comes to navigating sequentially through your site&#8217;s chronological archive pages, category archives, and other types of archive pages, [...]]]></description>
			<content:encoded><![CDATA[<p>There are many ways to navigate a WordPress-powered site. There are archive links, category links, page links, internal post links, single post links, admin comment links, tag links, and many other types of navigational links. When it comes to navigating sequentially through your site&rsquo;s chronological archive pages, category archives, and other types of archive pages, WordPress provides several useful template tags designed to dynamically link the pages together. Likewise, for single permalink post-views, WordPress provides a set of template tags that connects the pages together in chronologically sequential fashion.</p>
<p>When used properly, these page-navigation template tags enable your visitors to browse your site quickly and easily. Unfortunately, these different template tags have similar names, parameters, and functionality, thereby leaving many WordPress designers dazed and confused. </p>
<blockquote><p>In this <acronym title="Digging into WordPress">DiW</acronym> article, we&rsquo;ll dig into each of these different navigational tags and explain each of them in-depth, with plenty of juicy examples to help you take advantage of their full functionality.</p></blockquote>
<p>Here are the three sets of template tags we&rsquo;ll be exploring (click on a tag name to jump to that section):</p>
<p><span id="more-560"></span></p>
<ul id="navmenu">
<li>Index and archive navigation: <a href="#postsnavlink" title="posts_nav_link()">posts_nav_link()</a></li>
<li>Index and archive navigation: <a href="#previouspostslink" title="previous_posts_link() and next_posts_link()">previous_posts_link() and next_posts_link()</a></li>
<li>Single-view posts navigation: <a href="#previouspostlink" title="previous_post_link() and next_post_link()">previous_post_link() and next_post_link()</a></li>
</ul>
<h3 id="postsnavlink">posts_nav_link() &#8212; paired links for index, category, and archive pages</h3>
<p><small>[&nbsp;<a href="#navmenu" title="Return to post menu">&uarr;</a>&nbsp;]</small> <strong>The <code>posts_nav_link()</code> template tag provides a combined pair of &ldquo;next&rdquo; and &ldquo;previous&rdquo; navigational links for any type of paged archive view.</strong> Basically, this tag creates paired navigational links for anything other than single-post views. This includes index, category, archive, tag, and search pages. Best results when used either before or after the loop. Here is an example of the tag showing its three accepted parameters:</p>
<pre><code>&lt;?php posts_nav_link('sep','prelabel','nxtlabel'); ?&gt;</code></pre>
<h4>Default usage</h4>
<p>Here is the default usage of this template tag, followed by its corresponding output:</p>
<p><code>&lt;?php posts_nav_link(); ?&gt;</code></p>
<p><a href="#">&laquo; Previous Page</a> &#8212; <a href="#">Next Page &raquo;</a></p>
<h4>Parameters</h4>
<p>Values for each of the following parameters are strings that may be specified in alphanumeric characters or <acronym title="(eXtensible) Hypertext Markup Language">(X)HTML</acronym> markup:</p>
<p><code>&lt;?php posts_nav_link('sep','prelabel','nxtlabel'); ?&gt;</code></p>
<ul>
<li><code>sep</code> &#8212; text/markup that is displayed between the links</li>
<li><code>prelabel</code> &#8212; text/markup that is used as the link text for the previous page</li>
<li><code>nxtlabel</code> &#8212; text/markup that is used as the link text for the next page</li>
</ul>
<h4>Caution: it&rsquo;s all backward</h4>
<p>Keep in mind that the default implementation of the <code>posts_nav_link()</code> template tag generates links that are essentially backward in order: the &ldquo;Previous&nbsp;Page&rdquo; navigation link points to <em>newer</em> posts, while the &ldquo;Next&nbsp;Page&rdquo; navigation link points to <em>older</em> posts. Exactly the <em>opposite</em> of what you would expect. Normally, previous posts are older and next posts are newer. To fix this backward behavior, we <em>could</em> simply customize the link text of either navigation link like so:</p>
<pre><code>&lt;?php posts_nav_link(' &amp;bull; ','&amp;laquo; Go forward in time','Go back in time &amp;raquo;'); ?&gt;</code></pre>
<p>This would then generate the following links on your archive pages:</p>
<p><a href="#">&laquo; Go forward in time</a> &bull; <a href="#">Go back in time &raquo;</a></p>
<p>This reflects reality to a greater degree, however the links still seem to appear out of order. It just seems counter-intuitive to have the &ldquo;Go&nbsp;forward&rdquo; link on the left side of the page and the &ldquo;Go&nbsp;back&rdquo; link on the right side of the page. It seems more intuitive and natural to assume the reverse, link left to go back and link right to go forward. Just like reading a book.</p>
<p>Fortunately, there are two ways to get the links to appear in the reverse (i.e., correct) order. Both methods require us to separate the navigational links so that they may be repositioned with the &ldquo;Go&nbsp;back&rdquo; link on the left side of the page and the &ldquo;Go&nbsp;forward&rdquo; link on the right. How we go about separating the links depends on the template tag that is used. There is a workaround the <code>posts_nav_link()</code> tag, but it is far easier to simply use the <code>previous_posts_link()</code> and <code>next_posts_link()</code> tags instead. We&rsquo;ll get to the easy way in the next section; for now, let&rsquo;s look at the workaround for the <code>posts_nav_link()</code> tag.</p>
<p>To separate the navigational links created by the <code>posts_nav_link()</code> tag, we use <em>two</em> instances of it on the page. In the first instance, we kill the &ldquo;Go&nbsp;forward&rdquo; link, and in the second instance we kill the &ldquo;Go&nbsp;back&rdquo; link. The result is the following code, which provides us with two properly identified navigation links that may be situated in the correct order:</p>
<pre><code>&lt;?php posts_nav_link('','','Go back in time &amp;raquo;'); ?&gt; &amp;bull; &lt;?php posts_nav_link('','&amp;laquo; Go forward in time',''); ?&gt;</code></pre>
<p>Perhaps the best way to understand this technique is to sequentially test each of the following navigation templates. Along the way, keep an eye on where the links are appearing on the page and where the links are pointing:</p>
<pre><code>&lt;?php posts_nav_link(); // default tag ?&gt;

&lt;?php posts_nav_link(' &amp;bull; ','&amp;laquo; Go forward in time','Go back in time &amp;raquo;'); // switched text ?&gt;

&lt;?php posts_nav_link('','','Go back in time &amp;raquo;'); ?&gt; &amp;bull; &lt;?php posts_nav_link('','&amp;laquo; Go forward in time',''); // switched text and reversed order ?&gt;</code></pre>
<p>&ldquo;And that&rsquo;s all I have to say about that,&rdquo; as the man once said. Let&rsquo;s break out of this nightmare and move on to some fresh examples.</p>
<h4>Examples</h4>
<p>Here are some examples to demonstrate the use and flexibility of the <code>posts_nav_link()</code> template tag:</p>
<p><strong>Your basic navigation</strong></p>
<p>Out of the box, the <code>posts_nav_link()</code> template tag displays your navigation links in reverse order, but you can still customize the text to make things a little clearer for your readers. One of the benefits of sticking with the default busted configuration is that you will never have to deal with empty markup elements that may appear when there are no newer or older posts to display. If squeaky-clean source code tickles your fancy, customize the default tag as needed and enjoy the results:</p>
<pre><code>&lt;?php posts_nav_link(' &amp;bull; ','&amp;laquo; Go forward in time','Go back in time &amp;raquo;'); ?&gt;</code></pre>
<p><strong>Keep &lsquo;em separated</strong></p>
<p>What if you want to display your &ldquo;Previous&rdquo; link on the left side of the page and the &rdquo;Next&rdquo; link on the right side of the page? We can acheive this effect by using two instances of the <code>posts_nav_link()</code> template tag (note that this configuration also resolves the &ldquo;backward-navigation&rdquo; issue discussed above):</p>
<pre><code>&lt;div class="left"&gt;
	&lt;?php posts_nav_link('','','&amp;laquo; Older Posts'); ?&gt;
&lt;/div&gt;
&lt;div class="right"&gt;
	&lt;?php posts_nav_link('','Newer Posts &amp;raquo;',''); ?&gt;
&lt;/div&gt;</code></pre>
<p><strong>Keep &lsquo;em separated with images</strong></p>
<p>Continuing with the previous example, let&rsquo;s keep the navigation links separate, but use images instead of text:</p>
<pre><code>&lt;div class="left"&gt;
	&lt;?php posts_nav_link('','','&lt;img src="images/older.png" /&gt;'); ?&gt;
&lt;/div&gt;
&lt;div class="right"&gt;
	&lt;?php posts_nav_link('','&lt;img src="images/newer.png" /&gt;',''); ?&gt;
&lt;/div&gt;</code></pre>
<p>Remember, you can use any text or markup you need in this template tag, so knock yourself out and conjure up something fresh.</p>
<h3 id="previouspostslink">previous_posts_link() and next_posts_link() &#8212; separate links for index, category, and archive pages</h3>
<p><small>[&nbsp;<a href="#navmenu" title="Return to post menu">&uarr;</a>&nbsp;]</small> <strong>The <code>previous_posts_link()</code> and <code>next_posts_link()</code> template tags provide separate &ldquo;next&rdquo; and &ldquo;previous&rdquo; navigational links for any type of paged archive view.</strong> Basically, this tag creates individual navigational links for anything other than single-post views. This includes index, category, archive, tag, and search pages. Best results when used either before or after the loop. Here is an example of these tags showing their two accepted parameters:</p>
<pre><code>&lt;?php previous_posts_link('label','max_pages'); ?&gt;

&lt;?php next_posts_link('label','max_pages'); ?&gt;</code></pre>
<p><strong>Default usage</strong></p>
<p>Here is the default usage of these template tags, followed by their corresponding output (bullet added for clarity):</p>
<p><code>&lt;?php previous_posts_link(); ?&gt; &amp;bull; &lt;?php next_posts_link(); ?&gt;</code></p>
<p><a href="#">&laquo; Previous Page</a> &bull; <a href="#">Next Page &raquo;</a></p>
<h4>Parameters</h4>
<p>Here are the accepted parameters for each of these template tags:</p>
<p><code>&lt;?php previous_posts_link('label','max_pages'); ?&gt;</code><br />
<code>&lt;?php next_posts_link('label','max_pages'); ?&gt;</code></p>
<ul>
<li><code>label</code> &#8212; alphanumeric string and/or markup used for the link text</li>
<li><code>max_pages</code> &#8212; an integer that limits the number of pages on which the link is displayed. The default value is &ldquo;<code>0</code>&rdquo; for all pages.</li>
</ul>
<h4>These are backward too</h4>
<p>Like the <code>posts_nav_link()</code> tag, the <code>previous_posts_link()</code> and <code>next_posts_link()</code> create links that do the <em>opposite</em> of what you expect them to do. The <code>previous_posts_link()</code> tag links to <em>newer</em> posts and the <code>next_posts_link()</code> tag links to <em>older</em> posts. Again, exactly the opposite of what you would expect.</p>
<p>Fortunately, these tags create links that are <em>spearate</em> from one another, enabling us to implement them according to conventional methods of navigation. Simply customize the link text such that it means the <em>opposite</em> of the tag&rsquo;s name and then switch the tags&rsquo; order in the source code. Let&rsquo;s look at a few examples to help clarify this technique.</p>
<h4>Examples</h4>
<p>Here are some examples to demonstrate the use and flexibility of the <code>previous_posts_link()</code> and <code>next_posts_link()</code> template tags:</p>
<p><strong>Customized link text</strong></p>
<p>To keep the navigation operating conventionally, simply switch the meaning of the link text to convey the <em>opposite</em> meaning of the template tag and then position the tags accordingly:</p>
<pre><code>&lt;?php next_posts_link('&amp;laquo; Previous posts'); ?&gt; &lt;?php previous_posts_link('Next posts &amp;raquo;'); ?&gt;</code></pre>
<p><strong>Default WordPress theme</strong></p>
<p>Even the default WordPress theme, Kubrick, uses this technique to display proper navigational links in the correct order and on opposite sides of the page: </p>
<pre><code>&lt;div class="navigation"&gt;
&lt;div class="alignleft"&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
&lt;div class="alignright"&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>Thus, we see how to use the <code>previous_posts_link()</code> and <code>next_posts_link()</code> template tags to easily display your post-archive navigational links appear in the conventional, intiuitive, and correct order. Problem solved.</p>
<p><strong>Keep &lsquo;em separated with images (best method)</strong></p>
<p>Here&rsquo;s the <em>proper</em> way to create navigational links using images instead of text:</p>
<pre><code>&lt;div class="left"&gt;
	&lt;?php next_posts_link('&lt;img src="images/older.png" /&gt;'); ?&gt;
&lt;/div&gt;
&lt;div class="right"&gt;
	&lt;?php previous_posts_link('&lt;img src="images/newer.png" /&gt;'); ?&gt;
&lt;/div&gt;</code></pre>
<p>And as before, you may use any text or markup with this template tag, making it possible to integrate into just about any design.</p>
<h3 id="previouspostlink">previous_post_link() and next_post_link() &#8212; separate links for single-view post navigation</h3>
<p><small>[&nbsp;<a href="#navmenu" title="Return to post menu">&uarr;</a>&nbsp;]</small> <strong>The <code>previous_post_link()</code> and <code>next_post_link()</code> template tags provide separate links to the previous post and next post, respectively</strong>. In doing so, these tags enable visitors to navigate chronologically through your single post permalink pages. These tags may be used anywhere on the <code>sinlge.php</code> template page, either in or out of the loop. Here is an example of these tags showing their four accepted parameters:</p>
<pre><code>&lt;?php next_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;

&lt;?php previous_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;</code></pre>
<h4>Default usage</h4>
<p>Unlike other navigational tags, <code>next_post_link()</code> and <code>previous_post_link()</code> eliminate navigational confusion and ambiguity by using actual post titles for their link text. Here are some examples of the default usage of these tags, followed by their corresponding output (bullet added for clarity):</p>
<p><code>&lt;?php previous_post_link(); ?&gt; &amp;bull; &lt;?php next_post_link(); ?&gt;</code></p>
<p>&laquo; <a href="#">Previous Post Title</a> &bull; <a href="#">Next Post Title</a> &raquo;</p>
<h4>Parameters</h4>
<p>Here are the accepted parameters for each of these template tags:</p>
<p><code>&lt;?php next_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;</code><br />
<code>&lt;?php previous_post_link('format','link','in_same_cat','excluded_categories'); ?&gt;</code></p>
<ul>
<li><code>format</code> &#8212; format string for the link. Here you specify the text/HTML to appear before and after the link. The link itself is specified according to the <code>link</code> parameter by including the <code>%link</code> variable in the format string. For example, a <code>format</code> value of &ldquo;<code>Next: %link &amp;raquo;</code>&rdquo; will result in the following output: &ldquo;Next <a href="#">The Post Title</a>&nbsp;&raquo;&rdquo;</li>
<li><code>link</code> &#8212; link text to display. Anything specified here will be used as the <code>%link</code> variable in the <code>format</code> parameter (see previous). By default, this parameter returns the post title via the <code>%title</code> variable. For example, a <code>link</code> parameter with a value of &ldquo;<code>[[%title]]</code>&rdquo; will result in the following output: &ldquo;<a href="#">[[The Post Title]]</a>&nbsp;&raquo;&rdquo;</li>
<li><code>in_same_cat</code> &#8212; boolean value indicating whether or not the next or previous post must be in the same category as the current post. If set to <code>TRUE</code>, only posts from the current category will be displayed. Options are: <code>TRUE</code> or <code>FALSE</code> (default).</li>
<li><code>excluded_categories</code> &#8212; string indicating any collection of category IDs from which the next post should not be listed. In all versions of WordPress except 2.2, multiple categories are separated via &ldquo;<code> and </code>&rdquo;, for example: &lsquo;<code>1 and 3 and 7</code>&rsquo; Oddly enough, in WordPress version 2.2, a comma is used to concatenate multiple excluded categories, for example: &lsquo;<code>1, 3, 7</code>&rsquo;</li>
</ul>
<h4>Examples</h4>
<p>Here are some examples to demonstrate the use and flexibility of the <code>previous_post_link()</code> and <code>next_post_link()</code> template tags:</p>
<p><strong>Custom title with link description before/after post link</strong></p>
<p>Here we are displaying custom link titles with the text &ldquo;Previous&nbsp;post:&nbsp;&rdquo; and &ldquo;Next&nbsp;post:&nbsp;&rdquo; appearing before the previous and next post, respectively:</p>
<pre><code>&lt;?php previous_post_link('Previous post: %link', '[ %title ]'); ?&gt; &amp;bull; 
&lt;?php next_post_link('Next post: %link', '[ %title ]'); ?&gt;</code></pre>
<p><strong>Links to posts within the same category, excluding one</strong></p>
<p>Here is how to display next and previous post links only to posts that are in the same category as the current post unless the current post is in category <code>7</code>. Any number of categories may be excluded from this &ldquo;same-category&rdquo; navigation by using &ldquo;&nbsp;<code>and</code>&nbsp;&rdquo; as a delimiter:</p>
<pre><code>&lt;?php previous_post_link('%link', '%title', TRUE, '7'); ?&gt; &amp;bull; 
&lt;?php next_post_link('%link', '%title', TRUE, '7'); ?&gt;</code></pre>
<p><strong>Display images as links</strong></p>
<p>Instead of using text for the next/previous-post links, we can use a custom set of images:</p>
<pre><code>&lt;?php previous_post_link('%link', '&lt;img src="images/older.png" /&gt;', TRUE, '7'); ?&gt; &amp;bull; 
&lt;?php next_post_link('%link', '&lt;img src="images/newer.png" /&gt;', TRUE, '7'); ?&gt;</code></pre>
<p>Indeed, there is much that may done with this set of template tags. If you know of any juicy tricks not covered here, share them in the comments!</p>
<h3>One for the road</h3>
<p>Every now and then, you may encounter an older WordPress theme that includes the following navigation tags:</p>
<pre><code>&lt;?php previous_post(); ?&gt;
&lt;?php next_post(); ?&gt;</code></pre>
<p>For the record, these are the now-deprecated predecessors of the previously discussed <code>previous_post_link()</code> and <code>next_post_link()</code> template tags. The deprecated versions provide navigation of single permalink post views and use essentially the same parameters as the current tags. Now you know!&nbsp;:)</p>
<h3>References</h3>
<ul>
<li><a href="http://codex.wordpress.org/Template_Tags/posts_nav_link" title="WordPress Codex: posts_nav_link()">posts_nav_link()</a></li>
<li><a href="http://codex.wordpress.org/Template_Tags/previous_posts_link" title="WordPress Codex: previous_posts_link()">previous_posts_link()</a></li>
<li><a href="http://codex.wordpress.org/Template_Tags/next_posts_link" title="WordPress Codex: next_posts_link()">next_posts_link()</a></li>
<li><a href="http://codex.wordpress.org/Template_Tags/previous_post_link" title="WordPress Codex: previous_post_link()">previous_post_link()</a></li>
<li><a href="http://codex.wordpress.org/Template_Tags/next_post_link" title="WordPress Codex: next_post_link()">next_post_link()</a></li>
</ul>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/08/wordpress-page-navigation/">Permalink</a> | <a href="http://digwp.com/2009/08/wordpress-page-navigation/#comments">30 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/08/wordpress-page-navigation/&title=Definitive Guide to WordPress Page Navigation">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/navigation/" rel="tag">navigation</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/08/wordpress-page-navigation/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>Advanced WordPress Targeting with body_class_plus()</title>
		<link>http://digwp.com/2009/08/wordpress-body-class-plus/</link>
		<comments>http://digwp.com/2009/08/wordpress-body-class-plus/#comments</comments>
		<pubDate>Mon, 17 Aug 2009 03:56:30 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Plugins]]></category>
		<category><![CDATA[body]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[plugin]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=493</guid>
		<description><![CDATA[Since WordPress 2.8, we can target specific types of page views with CSS using the new body_class() tag. Designed for use within the &#60;body&#62; element, body_class() outputs various class attributes according to the current type of page view. This makes it easy to apply page-specific styling such as current-page navigation highlighting and other nifty CSS [...]]]></description>
			<content:encoded><![CDATA[<p>Since WordPress 2.8, we can target specific types of page views with <acronym title="Cascading Style Sheets">CSS</acronym> using the new <code>body_class()</code> tag. Designed for use within the <code>&lt;body&gt;</code> element, <code>body_class()</code> outputs various class attributes according to the current type of page view. This makes it easy to apply page-specific styling such as current-page navigation highlighting and other nifty <acronym title="Cascading Style Sheets">CSS</acronym> tricks.</p>
<p><span id="more-493"></span></p>
<h3>Strengths and shortcomings of the <code>body_class()</code> tag</h3>
<p>For the uninitiated, here is a quick review of the <code>body_class()</code> tag. When used as follows:</p>
<pre><code>&lt;body &lt;?php body_class(); ?&gt;&gt;</code></pre>
<p>The <code>body_class()</code> tag will output the following class names depending on current page type:</p>
<ul>
<li><code>.home</code> &#8212; class name output for the home page</li>
<li><code>.archive</code> &#8212; class name output for any archive page</li>
<li><code>.category</code> &#8212; class name output for any category page</li>
<li><code>.search</code> &#8212; class name output for any search page</li>
<li><code>.tag</code> &#8212; class name output for any tag archive page</li>
<li><a href="#attributes" title="View a complete list of body_class() attribute values">Plus many more..</a></li>
</ul>
<p>So, for example, when you are logged in to WordPress and viewing your blog&rsquo;s home page, the <code>body_class()</code> tag will result in something like this:</p>
<p><code>&lt;body class="home blog logged-in"&gt;</code></p>
<p>Or, if you were logged out and visiting your &ldquo;Asides&rdquo; category archive, your source code would include this:</p>
<p><code>&lt;body class="archive category category-asides"&gt;</code></p>
<p>This functionality enables you to, say, apply styles to the <code>&lt;h1&gt;</code> heading elements on all of your search pages:</p>
<pre><code>body.search h1 {
	border-bottom: 1px solid #ffff99;
	color: #ffff99;
	}</code></pre>
<p>Likewise, the class names output by the <code>body_class()</code> tag make it possible to target conditionally <em>any</em> element on <em>any</em> type of page, thereby greatly increasing the stylistic flexibility of WordPress. Yet despite its awesomeness, <code>body_class()</code> is essentially an &ldquo;all-or-nothing&rdquo; proposition. We can apply styles to <em>all</em> category pages, <em>all</em> search pages, <em>all</em> page pages, and so on. We can even use <acronym title="Cascading Style Sheets">CSS</acronym> chaining to target all category views when the user is logged in:</p>
<p><code>.home.logged-in {
	border: 100px solid red;
	}</code></p>
<p>This is powerful, yes, but what if we want to target, say, all categories that include the term &ldquo;services&rdquo; in the category slug? Sure, we could declare each of them individually, like this:</p>
<pre><code>.category-coffee-service { color: red; }
.category-brunch-services { color: red; }
.category-dinner-services { color: red; }
.category-snacks-services { color: red; }
.category-drinks-services { color: red; }
.category-inside-services { color: red; }
.category-design-services { color: red; }
.category-health-services { color: red; }
.category-services-info { color: red; }
.category-services-data { color: red; }
.category-services-cost { color: red; }</code></pre>
<p>But that&rsquo;s pretty inefficient. Plus, what if the user/client needed to create new &ldquo;services-related&rdquo; categories? Have fun explaining to them how edit the <acronym title="Cascading Style Sheets">CSS</acronym> file with the appropriate rules.</p>
<p>We could, I suppose, use <acronym title="Cascading Style Sheets">CSS</acronym>-3&rsquo;s wildcard substring-matching attribute-selector:</p>
<p><code>body[class*="services"] { color: red; }</code></p>
<p>Definitely cleaner, but there a significant number of browsers that do not support <acronym title="Cascading Style Sheets">CSS</acronym> 3, so this is less than an ideal solution. </p>
<p>A better solution would be to add pattern-matching functionality to the <code>body_class()</code> tag. After all, <code>body_class()</code> keeps track of just about every possible type of page-view available on your site. So why not filter the output of <code>body_class()</code> for any instances of &ldquo;services&rdquo; and output a specific class-attribute for all matching pages. This would allow us to target and apply styles to virtually <em>any</em> subset of page-views, including those new &ldquo;services-related&rdquo; categories for our client site. Say &ldquo;goodbye&rdquo; to manual code updating and say &ldquo;hello&rdquo; to automated advanced targeting with <code>body_class_plus()</code>.</p>
<h3>Advanced targeting with <code>body_class_plus()</code></h3>
<p>The <code>body_class_plus()</code> tag extends the functionality of <code>body_class()</code> by using <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>&rsquo;s output buffering to conditionally evaluate its contents. This functionality enables us to pattern-match for specific phrases, and execute conditional operations based on the contents of <code>body_class()</code>.</p>
<p>Here is the <code>body_class_plus()</code> function that may be placed in your <code>functions.php</code> file:</p>
<p><strong>Update:</strong> There is a new &amp; improved version of this code <a href="#downloads" title="Download the latest version of this code">available via plugin</a>!</p>
<pre><code>&lt;?php // http://digwp.com/2009/08/wordpress-body-class-plus/
function body_class_plus() { 
	if(function_exists('body_class')) { 
		ob_start(); body_class(); 
		$class = ob_get_contents(); 
		ob_end_clean(); 
		if($class) {
			if(preg_match("/services/i", $class)) { 
				echo 'class="services"';
			} elseif(preg_match("/products/i", $class)) {
				echo 'class="products"';
			} elseif(preg_match("/business/i", $class)) {
				echo 'class="business"';
			} elseif(preg_match("/pleasure/i", $class)) {
				echo 'class="pleasure"';
			} else {
				echo 'class="no-body-class-matches"';
			}
		} else { 
			echo 'class="body-class-not-available"'; 
		} 
	}
} ?&gt;</code></pre>
<p>To call this function in your theme template, include the following tag in the element of your choice (e.g., within the <code>&lt;body&gt;</code> element):</p>
<pre><code>&lt;?php if(function_exists('body_class_plus')) { body_class_plus(); } ?&gt;</code></pre>
<p>This is a exemplified version of the <code>body_class_plus()</code> function that enables us to target and apply specific class attributes to any page or category containing the following terms in the <acronym title="Uniform Resource Locator">URL</acronym>/page-slug:</p>
<ul>
<li>&ldquo;<code>services</code>&rdquo; &#8212; will apply <code>class="services"</code></li>
<li>&ldquo;<code>products</code>&rdquo; &#8212; will apply <code>class="products"</code></li>
<li>&ldquo;<code>business</code>&rdquo; &#8212; will apply <code>class="business"</code></li>
<li>&ldquo;<code>pleasure</code>&rdquo; &#8212; will apply <code>class="pleasure"</code></li>
</ul>
<p>This makes it easy to match specific groups of categories, pages, posts, or any combination thereof. Even better, the <code>body_class_plus()</code> function makes it possible to do more than apply classes to targeted page types. In addition to, or instead of, applying classes to specific groups of pages, you can implement any type of functionality desired. For example, you could display template tags, echo content, or execute custom scripts depending on page type. The possibilities are endless.</p>
<h3 id="downloads">Download the plugin</h3>
<p>If custom functions aren&rsquo;t your thang, and you would rather implement this functionality via plugin, you can grab it here: </p>
<ul>
<li><a href="http://digwp.com/plugins/body-class-plus_v02.zip" title="Version 0.2 (latest version)">body-class-plus_v02.zip</a> (latest version)</li>
<li><a href="http://digwp.com/plugins/body-class-plus_v01.zip" title="Version 0.1 (original release)">body-class-plus_v01.zip</a> (original release)</li>
</ul>
<p>Thanks to <a href="http://kahi.cz/wordpress/" title="Kahi's WordPress Notes">Peter Kahoun</a> for contributing his expertise and improving the functionality of this plugin.</p>
<h3>Take-home message</h3>
<p>The take-home message is that the <code>body_class_plus()</code> function extends the functionality of the <code>body_class()</code> tag to target and apply styles to any particular subset or combination of page types. Further, the <code>body_class_plus()</code> function takes <code>body_class()</code> beyond the realm of <acronym title="Cascading Style Sheets">CSS</acronym>, making it possible to apply template tags, <acronym title="PHP: Hypertext Preprocessor">PHP</acronym>, and other scripts to virtually any custom-defined set of pages and page types.</p>
<h3 id="attributes">Complete list of body_class() attribute values</h3>
<p>Here is a complete list of the available classes for the <code>body_class()</code> tag:</p>
<ul>
<li>rtl</li>
<li>home</li>
<li>blog</li>
<li>archive</li>
<li>date</li>
<li>search</li>
<li>paged</li>
<li>attachment</li>
<li>error404</li>
<li>single postid-(id)</li>
<li>attachmentid-(id)</li>
<li>attachment-(mime-type)</li>
<li>author</li>
<li>author-(user_nicename)</li>
<li>category</li>
<li>category-(slug)</li>
<li>tag</li>
<li>tag-(slug)</li>
<li>page-parent</li>
<li>page-child parent-pageid-(id)</li>
<li>page-template page-template-(template file name)</li>
<li>search-results</li>
<li>search-no-results</li>
<li>logged-in</li>
<li>paged-(page number)</li>
<li>single-paged-(page number)</li>
<li>page-paged-(page number)</li>
<li>category-paged-(page number)</li>
<li>tag-paged-(page number)</li>
<li>date-paged-(page number)</li>
<li>author-paged-(page number)</li>
<li>search-paged-(page number)</li>
</ul>
<p>For more ways to dynamically set body IDs, check out my article, <a href="http://perishablepress.com/press/2009/05/26/dynamic-body-class-id-php-wordpress/" title="9 Ways to Set Dynamic Body IDs via PHP and WordPress">9 Ways to Set Dynamic Body IDs via PHP and WordPress</a>.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/08/wordpress-body-class-plus/">Permalink</a> | <a href="http://digwp.com/2009/08/wordpress-body-class-plus/#comments">16 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/08/wordpress-body-class-plus/&title=Advanced WordPress Targeting with body_class_plus()">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/body/" rel="tag">body</a>, <a href="http://digwp.com/tag/css/" rel="tag">CSS</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/plugin/" rel="tag">plugin</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/08/wordpress-body-class-plus/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Awesome Image-Attachment Recipes for WordPress</title>
		<link>http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/</link>
		<comments>http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/#comments</comments>
		<pubDate>Mon, 10 Aug 2009 06:10:05 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[attachments]]></category>
		<category><![CDATA[images]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=458</guid>
		<description><![CDATA[Recently, I found myself on the front lines of WordPress&#8217; somewhat complicated Media-Library system. The site that I was developing required a rather elaborate system of retrieving and displaying image attachments. So, using the latest version of WordPress (2.8.3 at the time), I found myself experimenting with as many template tags and custom functions as [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, I found myself on the front lines of WordPress&rsquo; somewhat complicated Media-Library system. The site that I was developing required a rather elaborate system of retrieving and displaying image attachments. So, using the latest version of WordPress (2.8.3 at the time), I found myself experimenting with as many template tags and custom functions as I could find. After much experimentation, I discovered the perfect solution, and along the way I collected a healthy collection of recipes for displaying image attachments and their various types of associated information.</p>
<p>In this <acronym title="Digging into WordPress">DiW</acronym> article, you will learn some tasty ways to include image-attachment information in your posts. From echoing the latest image path to displaying custom-sized image-links for all post attachments, this article should serve as an invaluable resource for anyone working with WordPress&rsquo; Media Library and its media-attachment functionality.</p>
<p><span id="more-458"></span></p>
<h3>Basic display of gallery attachments</h3>
<p>When displaying your images via the <code>[gallery]</code> shortcode, WordPress will display image-links for each image in the gallery. Each of these image-links points to the image-gallery page for that particular image. The image gallery is created by the <code>image.php</code> template if present in your theme files. Here is a basic way to display your gallery images from within the image-gallery loop:</p>
<pre><code>&lt;a href="&lt;?php echo wp_get_attachment_url($post-&gt;ID); ?&gt;"&gt;&lt;?php echo wp_get_attachment_image($post-&gt;ID, 'medium'); ?&gt;&lt;/a&gt;</code></pre>
<p>This code will display a medium-sized image-link to the original image. To display an image attachment of a different size, replace the <code>$size</code> parameter in the <code>wp_get_attachment_image()</code> template tag. Accepted values are <code>thumbnail</code>, <code>medium</code>, <code>large</code>, or <code>full</code>. The actual dimensions of these sizes are determined by your preferences in the Media panel of the WordPress Admin.</p>
<h3>Display the URL of the latest image attachment</h3>
<p>Perhaps the most useful template tag for displaying image-attachment information is <code>wp_get_attachment_url()</code>. This function returns a full <acronym title="Uniform Resource Identifier">URI</acronym> for an attachment file. If no attachment is found, a value of <code>false</code> is returned. Here are several ways to use this tag within the loop:</p>
<pre><code>&lt;?php // display the attachment URI for post with specified ID
echo wp_get_attachment_url(7); ?&gt;

&lt;?php // display the latest attachment URI for each post from within the image.php loop
echo wp_get_attachment_url($post-&gt;ID); ?&gt;

&lt;?php // display the latest attachment URI for each post from within the index.php loop
echo wp_get_attachment_url($attachment_id); ?&gt;</code></pre>
<p>The output of this tag is similar to the following for each attachment:</p>
<p><code>http://digwp.com/wp-content/uploads/2009/08/example.png</code></p>
<p>If you are using the <code>image.php</code> file to display your attachments, use the second recipe to display the latest <acronym title="Uniform Resource Identifier">URI</acronym> for each post. If you are displaying your attachments from any other template file (e.g., <code>index.php</code>, <code>single.php</code>, etc.), use the third recipe and refer to <a href="#dynamic-post-id" title="Jump!">this section</a> of the article for the code required to generate dynamically the <code>$attachment_id</code> variable for the post ID.</p>
<h3>Display the latest image attachment as an image</h3>
<p>The <code>wp_get_attachment_image()</code> template tag is used to display the latest image attachment as an actual <acronym title="Hypertext Markup Language">HTML</acronym> image element. If no image attachment is found, a value of <code>false</code> is returned. Here are several ways to use this tag within the loop:</p>
<pre><code>&lt;?php // display medium-sized attached image for post with specified ID
echo wp_get_attachment_image(7, 'medium'); ?&gt;

&lt;?php // display the latest attached image for each post from within the image.php loop
echo wp_get_attachment_image($post-&gt;ID); ?&gt;

&lt;?php // display the latest attached image for each post from within the index.php loop
echo wp_get_attachment_image($attachment_id); ?&gt;</code></pre>
<p>The output of this tag is similar to the following for each attachment:</p>
<p><code>&lt;img src="http://digwp.com/wp-content/uploads/2009/08/example.png" class="attachment-thumbnail" height="50" width="50"&gt;</code></p>
<p>The <code>wp_get_attachment_image()</code> template tag may be customized with the following parameters:</p>
<p><code>&lt;?php wp_get_attachment_image($attachment_id, $size='thumbnail', $icon=false); ?&gt;</code></p>
<ul>
<li><code>$attachment_id</code> &#8212; ID of the desired attachment. Not required if used within an attachment loop, otherwise, refer to <a href="#dynamic-post-id" title="Jump!">this section</a> to generate the ID for non-attachment loops.</li>
<li><code>$size</code> &#8212; Size of the image shown for an image attachment: <code>thumbnail</code>, <code>medium</code>, <code>large</code> or <code>full</code></li>
<li><code>$icon</code> &#8212; (Optional) Use a media icon to represent the attachment. Default value: <code>false</code>.</li>
</ul>
<h3>Display the thumbnail of the latest image attachment</h3>
<p>I couldn&rsquo;t find any official documentation for the <code>get_attachment_icon()</code> template tag, but after some experimentation, it seems useful for displaying a thumbnail of the latest image attachment for each post. Here are some examples:</p>
<pre><code>&lt;?php // display image thumbnail for post with specified ID
echo get_attachment_icon(7); ?&gt;

&lt;?php // display image thumbnail for each post from within the image.php loop
echo get_attachment_icon($post-&gt;ID); ?&gt;

&lt;?php // display image thumbnail for each post from within the index.php loop
echo get_attachment_icon($attachment_id); ?&gt;</code></pre>
<p>The output of this tag is similar to the following for each attachment:</p>
<p><code>&lt;img src="http://digwp.com/wp-content/uploads/2009/08/example.png" title="example" alt="example"&gt;</code></p>
<p>If using this tag within an attachment loop, such as in the <code>image.php</code> or <code>attachment.php</code> theme file, the post ID parameter is generated automatically. If using within a non-attachment loop, such as in the <code>index.php</code> or <code>single.php</code> theme file, refer to <a href="#dynamic-post-id" title="Jump!">this section</a> for the code required to generate dynamically the post-ID variable.</p>
<h3>Other useful template tags for displaying image attachments</h3>
<p>Here are some other useful template tags for displaying image attachments and their related information:</p>
<pre><code>&lt;?php // returns the URL for the latest attachment thumbnail
wp_get_attachment_thumb_url($attachment_id); ?&gt;

&lt;?php // returns an image representing the latest attachment file
wp_get_attachment_image_src($attachment_id, $size='thumbnail', $icon=false); ?&gt;

&lt;?php // returns an image-link or text-link to the latest attachment file or attachment page
wp_get_attachment_link($id=0, $size='thumbnail', $permalink=false, $icon=false); 

&lt;?php // displays an image link to the latest attachment file
the_attachment_link($attachment_id); ?&gt;

&lt;?php // returns an image link to the latest attachment file
get_the_attachment_link($attachment_id);  ?&gt;

&lt;?php // returns a URI to the attachment page for the latest attachment
get_attachment_link($attachment_id);  ?&gt;</code></pre>
<p>See the next section for generating the values of the <code>$attachment_id</code> variable.</p>
<h3 id="dynamic-post-id">Dynamic generation of the post ID for non-attachment loops</h3>
<p>If you are using any of the above recipes within a <code>single.php</code>, <code>index.php</code>, or any other non-attachment loop, you will need to include the following line of code to generate the ID for each post:</p>
<pre><code>&lt;?php global $wpdb; $attachment_id = $wpdb-&gt;get_var("SELECT ID FROM $wpdb-&gt;posts WHERE post_parent = '$post-&gt;ID' 
AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1"); ?&gt;</code></pre>
<p>This code dynamically generates the <code>$attachment_id</code> variable that is used in some of the examples above. Here is an example showing how to display the latest attachment <acronym title="Uniform Resource Identifier">URI</acronym> for each post from within the <code>index.php</code> loop:</p>
<pre><code>&lt;?php global $wpdb; $attachment_id = $wpdb-&gt;get_var("SELECT ID FROM $wpdb-&gt;posts WHERE post_parent = '$post-&gt;ID' 
AND post_status = 'inherit' AND post_type='attachment' ORDER BY post_date DESC LIMIT 1"); 
echo wp_get_attachment_url($attachment_id); ?&gt;</code></pre>
<p>Enough of the simple stuff! Let&rsquo;s move on to some more <em>advanced</em> recipes.</p>
<h3>Display all attachments for each post</h3>
<p>Up to this point, we have been using template tags to display information related to the <em>latest attachment</em> only. With any of the above methods, the output for any of the template tags represents a <em>single</em> attachment item. In order to display <em>multiple</em> attachments for each post, we need to employ WordPress&rsquo; <code>get_children()</code> functionality. The <code>get_children()</code> tag returns an associative array of posts with post IDs as array keys. The default parameters are as follows (as of version 2.7):</p>
<pre><code>$defaults = array( 
	'post_parent' =&gt; 0,     // get children of this post ID; null value gets all children
	'post_type'   =&gt; 'any', // post type: attachment, page, revision, or any; default: any
	'numberposts' =&gt; -1,    // number of child posts to retrieve; default: -1 (unlimited)
	'post_status' =&gt; 'any', // post status: publish, draft, inherit, or any; default: any
);</code></pre>
<p>For (cough) complete information (cough), refer to the <a href="http://codex.wordpress.org/Function_Reference/get_children" title="WordPress Codex: get_children()">official documentation</a>.</p>
<p>Using this functionality, we are well-equipped to use any of the previously discussed template tags (or any other attachment-related tag) to display all of the attachments for each post in the loop. Here is the basic technique, using the <code>wp_get_attachment_link()</code> template tag:</p>
<pre><code>&lt;?php 
$args = array(
	'order'          =&gt; 'ASC',
	'post_type'      =&gt; 'attachment',
	'post_parent'    =&gt; $post-&gt;ID,
	'post_mime_type' =&gt; 'image',
	'post_status'    =&gt; null,
	'numberposts'    =&gt; -1,
);
$attachments = get_posts($args);
if ($attachments) {
	foreach ($attachments as $attachment) {
		echo apply_filters('the_title', $attachment-&gt;post_title);
		echo wp_get_attachment_link($attachment-&gt;ID, 'thumbnail', false, false);
	}
}
?&gt;</code></pre>
<p>When used within the loop, this code will output the title and thumbnail-size image-link for <em>every</em> attachment of each post within the loop. As is, the image-links point to the <acronym title="Uniform Resource Identifier">URI</acronym> of the original, full-size attachment file. To get the image-links to point to the attachment page for each image, change the third parameter in the <code>wp_get_attachment_link()</code> tag to <code>true</code>. </p>
<p>Currently, the function will display <em>all</em> attachments for each post. To limit the number of attachments displayed, change the <code>numberposts</code> value from &ldquo;<code>-1</code>&rdquo; to whatever number you wish.</p>
<p>Once you get the hang of this basic attachment-display method, you can have some fun experimenting with different output formats by swapping out and/or including additional template tags. For example, instead of displaying a thumbnail link along with the attachment title, you may want to display the <acronym title="Uniform Resource Identifier">URI</acronym> of the original attachment. To do so, you would simply replace this line:</p>
<p><code>echo wp_get_attachment_link($attachment-&gt;ID, 'thumbnail', false, false);</code></p>
<p>..with this:</p>
<p><code>wp_get_attachment_url($attachment-&gt;ID)</code></p>
<p>Now, what about all of the other tags? How to implement and integrate them into a cohesive configuration of image-attachment bliss? There are far too many possible configurations to even begin to cover them all, but I did come up with an effective way of demonstrating the configurational possibilities with a little function I like to call the &ldquo;Attachment&nbsp;Toolbox&rdquo;.</p>
<h3>Image-attachment enlightenment with the Attachment Toolbox</h3>
<p>The idea is simple: <strong>learn by example</strong>. This function is essentially a &ldquo;live&rdquo; demonstration of the various template tags and their generated output. To use this function, create a few posts and attach some images (or other types of attachments) to each of them. Then, place the following code into your theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>&lt;?php 
function attachment_toolbox($size = thumbnail) {

	if($images = get_children(array(
		'post_parent'    =&gt; get_the_ID(),
		'post_type'      =&gt; 'attachment',
		'numberposts'    =&gt; -1, // show all
		'post_status'    =&gt; null,
		'post_mime_type' =&gt; 'image',
	))) {
		foreach($images as $image) {
			$attimg   = wp_get_attachment_image($image-&gt;ID,$size);
			$atturl   = wp_get_attachment_url($image-&gt;ID);
			$attlink  = get_attachment_link($image-&gt;ID);
			$postlink = get_permalink($image-&gt;post_parent);
			$atttitle = apply_filters('the_title',$image-&gt;post_title);

			echo '&lt;p&gt;&lt;strong&gt;wp_get_attachment_image()&lt;/strong&gt;&lt;br /&gt;'.$attimg.'&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;wp_get_attachment_url()&lt;/strong&gt;&lt;br /&gt;'.$atturl.'&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;get_attachment_link()&lt;/strong&gt;&lt;br /&gt;'.$attlink.'&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;get_permalink()&lt;/strong&gt;&lt;br /&gt;'.$postlink.'&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;Title of attachment&lt;/strong&gt;&lt;br /&gt;'.$atttitle.'&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;Image link to attachment page&lt;/strong&gt;&lt;br /&gt;&lt;a href="'.$attlink.'"&gt;'.$attimg.'&lt;/a&gt;&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;Image link to attachment post&lt;/strong&gt;&lt;br /&gt;&lt;a href="'.$postlink.'"&gt;'.$attimg.'&lt;/a&gt;&lt;/p&gt;';
			echo '&lt;p&gt;&lt;strong&gt;Image link to attachment file&lt;/strong&gt;&lt;br /&gt;&lt;a href="'.$atturl.'"&gt;'.$attimg.'&lt;/a&gt;&lt;/p&gt;';
		}
	}
}
?&gt;</code></pre>
<p>Then, in your <code>index.php</code> or <code>single.php</code> (or other non-attachment) loop, call the function with the following tag:</p>
<pre><code>&lt;?php attachment_toolbox('thumbnail'); ?&gt;</code></pre>
<p>Then check the results in your browser. You will see that the code has output a variety of different attachment data, including title, attachment URI, post URI, image URI, image thumbnail, image links, and so on. After examining the output, refer back to the function itself to understand the functionality of each tag. Once you begin to see the correlation between source code and page output, you will be well equipped to transform the function in any way you see fit, or even use it as a guide to create your own custom attachment-display function. It&rsquo;s all there, just dig in and check it out&nbsp;:)</p>
<h3>Check please</h3>
<p>That does it for this fun-filled <acronym title="Digging into WordPress">DiW</acronym> article. We have seen how to display many different types of image-attachment information, including everything from thumbnail links and <acronym title="Uniform Resource Locator">URL</acronym> paths to custom-sized images and multiple attachments. This collection of recipes is by no means exhaustive, but it provides plenty of key techniques to help implement and customize your own image-attachment functionality. Working with WordPress&rsquo; Media Library can be a convoluted process, to say the least, so any tips and tricks that you happen to know will be greatly appreciated by the incredibly awesome WordPress community.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/">Permalink</a> | <a href="http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/#comments">46 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/&title=Awesome Image-Attachment Recipes for WordPress">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/attachments/" rel="tag">attachments</a>, <a href="http://digwp.com/tag/images/" rel="tag">images</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/feed/</wfw:commentRss>
		<slash:comments>46</slash:comments>
		</item>
		<item>
		<title>Delicious Recipes for WordPress Page Menus and Page Listings</title>
		<link>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/</link>
		<comments>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/#comments</comments>
		<pubDate>Mon, 13 Jul 2009 15:01:50 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[pages]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=248</guid>
		<description><![CDATA[There are so many awesome ways to display your WordPress pages. Out of the box, WordPress provides two different template tags for displaying lists of your site&#8217;s pages. The first, most-commonly used tag is wp_list_pages(), and the second, lesser-known tag is wp_page_menu(). First we&#8217;ll explore the highly flexible wp_list_pages() template tag, and then we&#8217;ll dig [...]]]></description>
			<content:encoded><![CDATA[<p>There are so many awesome ways to display your WordPress pages. Out of the box, WordPress provides two different template tags for displaying lists of your site&rsquo;s pages. The first, most-commonly used tag is <code>wp_list_pages()</code>, and the second, lesser-known tag is <code>wp_page_menu()</code>. First we&rsquo;ll explore the highly flexible <code>wp_list_pages()</code> template tag, and then we&rsquo;ll dig into the new <code>wp_page_menu()</code> tag. Along the way, we&rsquo;ll check out some delicious recipes, tips and tricks for creating the perfect WordPress Page Menu.</p>
<p><span id="more-248"></span></p>
<h3>Digging into the wp_list_pages() template tag</h3>
<p>Almost everyone is familiar with the <code>wp_list_pages()</code> template tag, and it has served us well since WordPress version 1.5. Using this tag is easy, just add the following code to your sidebar or other choice location:</p>
<pre><code>&lt;?php wp_list_pages(); ?&gt;</code></pre>
<p>And then you can customize that in many ways using the fine menu of arguments provided at its <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages" title="WordPress Codex: Template Tags/wp_list_pages">Codex Reference Page</a>. Some of the highlights include:</p>
<h3>Extreme Sorting Power</h3>
<p>You can sort your pages by the descriptor of any field in the <code>wp_post</code> table of the WordPress database. By default, you get alphabetical by page title, but there are some other great options as well. Here are some delicious copy-&amp;-paste recipes for your next project:</p>
<pre><code>&lt;?php wp_list_pages('sort_column=menu_order'); // sort by admin-specified order ?&gt;
&lt;?php wp_list_pages('sort_column=post_date'); // sort by time of page creation ?&gt;
&lt;?php wp_list_pages('sort_column=post_name'); // sort by name of the page slug ?&gt;
&lt;?php wp_list_pages('sort_column=id&amp;sort_order=asc'); // page id in ascending order ?&gt;
&lt;?php wp_list_pages('sort_column=id&amp;sort_order=desc'); // page id in descending order ?&gt;</code></pre>
<p>That first one there is a little wonky, but can prove very helpful for getting your pages to display in <em>any</em> order imaginable. To configure custom Page order to display via the <code>menu_order</code> parameter, you simply assign each Page a numerical value in its Write/Edit Admin screen. You can see a full list of available descriptors <a href="http://codex.wordpress.org/Database_Description#Table:_wp_posts" title="WordPress Codex: Description of the wp_posts Table">here</a>.</p>
<h3>Include and Exclude Anything</h3>
<p>WordPress makes it easy to include and exclude any pages to create the perfect page menu. By default, the <code>wp_list_pages</code> displays all pages, but this is easily customized with three useful arguments:</p>
<pre><code>&lt;?php wp_list_pages('exclude=1,2,3'); // exclude only these three page ids ?&gt;
&lt;?php wp_list_pages('include=1,2,3'); // include only these three page ids ?&gt;
&lt;?php wp_list_pages('exclude_tree=1,2,3'); // exclude these parent pages and all children ?&gt;</code></pre>
<p>The <code>exclude_tree</code> parameter is new as of WordPress version 2.7. It makes it super-easy to omit an entire branch of pages (the parent page and all descendant pages) from your page listings.</p>
<h3>Control the Depth of Pages</h3>
<p>There are two parameters designed to control the depth of pages displayed by the <code>wp_list_pages()</code> tag. The first is the <code>depth</code> parameter, which by default displays all subpages, regardless of depth. There is also the <code>child_of</code> parameter, which defaults to a value of <code>0</code> to display all pages and subpages. Here are some recipes to customize these default values:</p>
<pre><code>&lt;?php wp_list_pages('depth=0'); // display all pages and subpages via indented lists ?&gt;
&lt;?php wp_list_pages('depth=-1'); // display all pages and subpages without indentation ?&gt;
&lt;?php wp_list_pages('depth=1'); // display only top-level pages ?&gt;
&lt;?php wp_list_pages('depth=2'); // display all pages and first level subpages ?&gt;
&lt;?php wp_list_pages('depth=n'); // display all pages and subpages to the nth level ?&gt;

&lt;?php wp_list_pages('child_of=0'); // displays all pages and subpages ?&gt;
&lt;?php wp_list_pages('child_of=3'); // displays all subpages of page with id 3 ?&gt;</code></pre>
<p>The <code>child_of</code> parameter is a great way to display sub-menus of specific pages, for example for implementation of drop-down menus and so forth. Note that multiple instances of <code>wp_list_pages()</code> may be used on any given web page.</p>
<h3>Use with Custom Fields</h3>
<p>Here is an extremely powerful way to customize your page menus using custom-field values. Using <code>meta_key</code> and <code>meta_value</code> parameters, you can tell WordPress to display only those pages that contain specific custom-field key/value pairs. Here are some examples:</p>
<pre><code>&lt;?php wp_list_pages('meta_key=menu&amp;meta_value=page'); // display pages with menu/page custom field ?&gt;
&lt;?php wp_list_pages('meta_key=icon&amp;meta_value=true'); // display pages with icon/true custom field ?&gt;</code></pre>
<p>This parameter also gives you the flexibility of modifying page listings without having to touch any source code. Great for clients and family members who may not feel comfortable &ldquo;digging in&rdquo;&nbsp;;)</p>
<h3>Even more functionality (new in WordPress 2.7 &amp; 2.8)</h3>
<p>WordPress recently rolled out some new tricks for the <code>wp_list_pages()</code> tag. Namely, we now have the ability to wrap the anchor text of our page listings with any <acronym title="Hypertext Markup Language">HTML</acronym> or text. Other new features include the number of pages to display as well the number of pages to pass over when displaying page listings. Let&rsquo;s have a look:</p>
<pre><code>&lt;?php wp_list_pages('link_before=&lt;span&gt;&amp;link_after=&lt;/span&gt;'); // wrap anchor text with a span tag ?&gt;
&lt;?php wp_list_pages('number=7'); // display only the first seven pages ?&gt;
&lt;?php wp_list_pages('offset=7'); // skip the first seven pages ?&gt;</code></pre>
<h3>A complete copy/paste recipe for wp_list_pages()</h3>
<p>There are several more useful parameters for the <code>wp_list_pages()</code> tag, but rather than explaining each one, I will refer you to the <a href="http://codex.wordpress.org/Template_Tags/wp_list_pages" title="WordPress Codex: Template Tags/wp_list_pages">Codex</a> for all the boring details. So now, before digging into the juicy stuff, here is a &ldquo;super-delicious&rdquo; tag recipe equipped with <em>every</em> possible parameter, especially designed for easy customization:</p>
<pre><code>&lt;?php wp_list_pages('sort_column=post_title&amp;sort_order=asc&amp;exclude=0&amp;exclude_tree=0&amp;include=0&amp;depth=0&amp;child_of=0&amp;show_date=&amp;date_format=&amp;title_li=&amp;echo=1&amp;meta_key=menu&amp;meta_value=page&amp;link_before=&lt;span&gt;&amp;link_after=&lt;/span&gt;&amp;authors=0&amp;number=0&amp;offset=0'); // contains all parameters as of version 2.8 ?&gt;</code></pre>
<p>Alright, enough of the basics, let&rsquo;s explore some truly delicious page-listing recipes.</p>
<h3>List all subpages of current page</h3>
<p>Here is a way to simplify your sidebars and overall page designs. Instead of listing <em>every</em> subpage on all of your site&rsquo;s web pages, you can dynamically display subpages only when the visitor is viewing the parent page. So for example, your homepage sidebar would list all of your parent pages, and then each of the parent pages would display a list containing all of its subpages. Here&rsquo;s one way to do it, as demonstrated in the Codex:</p>
<pre><code>&lt;?php 
$children = wp_list_pages('title_li=&amp;child_of='.$post-&gt;ID.'&amp;echo=0');
if ($children) { ?&gt;
	&lt;ul&gt;
		&lt;?php echo $children; ?&gt;
	&lt;/ul&gt;
&lt;?php } ?&gt;</code></pre>
<p>Placed in your theme template file, this code will generate a list of all subpages for the current parent page. If there are no subpages, nothing will be displayed.</p>
<p>As is, this method will only display the subpages when visiting the parent page, but we can modify the code so that all subpages are displayed when visiting either the parent page or any of the subpages:</p>
<pre><code>&lt;?php
if($post-&gt;post_parent)
	$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;post_parent."&amp;echo=0");
else
	$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;ID."&amp;echo=0");
if ($children) { ?&gt;
	&lt;ul&gt;
		&lt;?php echo $children; ?&gt;
	&lt;/ul&gt;
&lt;?php } ?&gt;</code></pre>
<p>And you can do even better than that. With this next method, your page listings will be displayed as follows:</p>
<ul>
<li>When visiting main page, all top level pages are listed in the sidebar.</li>
<li>When visiting a top level page with no children, all top level pages are listed.</li>
<li>When visiting a top level page with children, just the children pages, and descendant pages, are listed.</li>
<li>When visiting a child page, just the children, and descendant pages, of that parent, are listed.</li>
</ul>
<pre><code>&lt;?php
$output = wp_list_pages('echo=0&amp;depth=1&amp;title_li=&lt;h2&gt;Top Level Pages&lt;/h2&gt;' );
if (is_page( )) {
	$page = $post-&gt;ID;
	if ($post-&gt;post_parent) {
		$page = $post-&gt;post_parent;
	}
	$children=wp_list_pages( 'echo=0&amp;child_of=' . $page . '&amp;title_li=' );
	if ($children) {
		$output = wp_list_pages ('echo=0&amp;child_of=' . $page . '&amp;title_li=&lt;h2&gt;Child Pages&lt;/h2&gt;');
	}
}
echo $output;
?&gt;</code></pre>
<p>All this is great, but it&rsquo;s also helpful to know how to style the markup generated by the <code>wp_list_pages()</code> template tag. Let&rsquo;s look at that next..</p>
<h3>Styling wp_list_pages() markup</h3>
<p>Here is the default markup generated by the <code>wp_list_pages()</code> template tag (assuming a total of five pages with the current page having an ID of &ldquo;<code>1</code>&rdquo;):</p>
<pre><code>&lt;li class="pagenav"&gt;Pages
	&lt;ul&gt;
		&lt;li class="page-item-1 page_item current_page_item"&gt;Page ID 1&lt;/li&gt;
		&lt;li class="page-item-2 page_item"&gt;Page ID 2&lt;/li&gt;
		&lt;li class="page-item-3 page_item"&gt;Page ID 3&lt;/li&gt;
		&lt;li class="page-item-4 page_item"&gt;Page ID 4&lt;/li&gt;
		&lt;li class="page-item-5 page_item"&gt;Page ID 5&lt;/li&gt;
	&lt;/ul&gt;
&lt;/li&gt;</code></pre>
<p>You can strip the outer <code>&lt;li class="pagenav"&gt;</code> and the enclosing <code>&lt;ul&gt;&lt;/ul&gt;</code> tags by including &ldquo;<code>title_li=</code>&rdquo; (empty string) as a parameter in the <code>wp_list_pages()</code> template tag. You may also keep these outer tags and customize the &ldquo;Pages&rdquo; text with whatever markup and/or text you need. Instead of an empty string, use something like &ldquo;<code>title_li=&lt;h2&gt;Pages&lt;/h2&gt;</code>&rdquo; instead. Note also that specific class attributes will be applied to both parents and ancestors of the current page (see next section).</p>
<h3>Styling page menus generated by wp_list_pages()</h3>
<p>Here is a list of the selectors available for styling your page menus:</p>
<pre><code>.pagenav {}               /* li tag containing page menu */
.page_item {}             /* inlcuded on every page item */
.page-item-n {}           /* specifies page with id of n */
.current_page_item {}     /* specifies the current page */
.current_page_parent {}   /* any parent of current page */
.current_page_ancestor {} /* any child of current page */</code></pre>
<p>Now, ready for some new stuff? Brace yourself..</p>
<h3>Digging into the wp_page_menu() template tag</h3>
<p>So what about this new <code>wp_page_menu()</code> template tag? With all of the flexibility of <code>wp_list_pages()</code>, why is it necessary? In a nutshell, <code>wp_page_menu()</code> is a simplified version of <code>wp_list_pages()</code>. In addition to accepting a few of the same parameters, this new tag brings one new trick to the table: <strong>it provides the ability to add your site&rsquo;s Home page to the list of Pages displayed</strong>. This tag was introduced in WordPress version 2.7, and, in my opinion, should have been integrated into the existing Page-listing template tag. In any case, for those looking for an easy way to include your Home page into the list of Pages, here you go:</p>
<pre><code>&lt;?php wp_page_menu(); ?&gt;</code></pre>
<p>As mentioned, most of the parameters are the same as before. Here is a list of common parameters:</p>
<ul>
<li><code>sort_column</code></li>
<li><code>include</code></li>
<li><code>echo</code></li>
<li><code>link_before</code></li>
<li><code>link_after</code></li>
</ul>
<p>And &#8212; drum roll please &#8212; here are the new parameters: <code>menu_class</code> and <code>show_home</code>! Let&rsquo;s check &lsquo;em out..</p>
<p><strong><code>menu_class</code></strong></p>
<p>This is a no-brainer. It simply specifies the <code>class</code> attribute for the surrounding <code>&lt;div&gt;</code>. Yes, the list is wrapped in a division. Any string may be used, here is an example:</p>
<pre><code>&lt;?php wp_page_menu('menu_class=pages'); // wrap list in div with class="pages" ?&gt;</code></pre>
<p><strong><code>show_home</code></strong></p>
<p>Ahh, the long-awaited &ldquo;include-the-home-page&rdquo; functionality. Now, instead of hacking your client&rsquo;s <code>functions.php</code> file to include the Home Page in the main menu, you can simply do this instead:</p>
<pre><code>&lt;?php wp_page_menu('show_home=1'); // include the home page in the list ?&gt;
&lt;?php wp_page_menu('show_home=0'); // exclude the home page in the list ?&gt;</code></pre>
<p>By default, this parameter returns false and no Home Page is displayed. When set to <code>true</code>, the Home Page will be displayed as the first item in the page list. The <acronym title="Uniform Resource Locator">URL</acronym> for the Home Page is taken from the value for your site&rsquo;s &ldquo;Blog address&rdquo;, as specified in the WordPress Admin under <code>Settings</code> &gt; <code>General</code>. </p>
<p>When the Home Page is displayed, the default anchor text is simply &ldquo;Home&rdquo;, but you can customize that to whatever you want by specifying such for the parameter value:</p>
<pre><code>&lt;?php wp_page_menu('show_home=Digging%20into%20WordPress'); // include the home page ?&gt;
&lt;?php wp_page_menu(array('show_home'=&gt;'Digging into WordPress', 'sort_column'=&gt;'menu_order')); // include the home page ?&gt;</code></pre>
<p>For more information on this new tag, check it out at the <a href="http://codex.wordpress.org/Template_Tags/wp_page_menu" title="WordPress Codex: Template Tags/wp_page_menu">WordPress Codex</a></p>
<h3>Take-home message</h3>
<p>WordPress provides two different ways to list your pages: <code>wp_page_menu()</code> and <code>wp_list_pages()</code>. The <code>wp_list_pages()</code> tag is powerful, flexible and fully functional. So, unless you need to include your Home Page, your best bet is always <code>wp_list_pages()</code>. For page menus that include the Home Page, you will need to use <code>wp_page_menu()</code> instead. Beyond listing your Home Page, the <code>wp_page_menu()</code> can do a <em>few</em> things, but nothing that <code>wp_list_pages()</code> can&rsquo;t already handle. </p>
<p>My question for the day is: Why wasn&rsquo;t the home-page functionality integrated into the existing tag? Why complicate things with an otherwise redundant tag? Share your thoughts!</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/">Permalink</a> | <a href="http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/#comments">59 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/&title=Delicious Recipes for WordPress Page Menus and Page Listings">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/pages/" rel="tag">pages</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/delicious-recipes-wordpress-page-menus/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>Add/Remove Buttons from WordPress Write Panel</title>
		<link>http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/</link>
		<comments>http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/#comments</comments>
		<pubDate>Tue, 23 Jun 2009 14:07:44 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Admin]]></category>
		<category><![CDATA[button]]></category>
		<category><![CDATA[editing]]></category>
		<category><![CDATA[tags]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=73</guid>
		<description><![CDATA[One of the features of WordPress 2.8 was a &#8220;increased speed of the Admin area&#8221;, which cited compressed JavaScript files as the reason for the speed increase. One of those files that was compressed was the file quicktags.js in the wp-includes/js directory. When you have the visual editor turned off, this is the file responsible [...]]]></description>
			<content:encoded><![CDATA[<p>One of the features of WordPress 2.8 was a &#8220;increased speed of the Admin area&#8221;, which cited compressed JavaScript files as the reason for the speed increase. One of those files that was compressed was the file <code>quicktags.js</code> in the <code>wp-includes/js</code> directory.</p>
<p><strong>When you have the visual editor turned off,</strong> this is the file responsible for created the buttons above the write panel. You know, the buttons like b for strong tags, i for em tags, b-quote for blockquote tags, etc. Personally I much prefer this to the Visual Editor, as I can see exactly what tags are being applied to my content. </p>
<p><img src="http://digwp.com/wp-content/blog-images/tags.png" width="457" height="34" alt="" title="" /></p>
<p><span id="more-73"></span></p>
<p>But those default buttons are often not quite enough. I like to have a few more buttons easily available to me, like ones for h3-h5 tags, one that will wrap text in both code <strong>and</strong> pre tags, and one for a float-clearing div.</p>
<p>But remember in WordPress 2.8, this quicktags.js file is now compressed so it cannot be easily altered to include these new buttons like it used to. Thankfully they left a non-compressed version of the file in there as well, called <code>quicktags.dev.js</code>. To use this instead, just rename the quicktags.js file something like quicktags.ORIG.js and rename <code>quicktags.dev.js</code> into <code>quicktags.js</code>.</p>
<p>To add a new h3 button, add a block of code like this, amongst all the other similar code blocks:</p>
<pre><code>edButtons[edButtons.length] =
new edButton('ed_h3'
,'h3'
,'&amp;lt;h3&amp;gt;'
,'&amp;lt;/h3&amp;gt;'
,'h3'
);</code></pre>
<p>Force refresh your Edit Post page and you should see the new button!</p>
<p><img src="http://digwp.com/wp-content/blog-images/tags2.png" width="443" height="35" alt="" title="" /></p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/">Permalink</a> | <a href="http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/#comments">20 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/&title=Add/Remove Buttons from WordPress Write Panel">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/button/" rel="tag">button</a>, <a href="http://digwp.com/tag/editing/" rel="tag">editing</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/06/addremove-buttons-from-wordpress-write-panel/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Custom WordPress Title Tags</title>
		<link>http://digwp.com/2009/06/custom-wordpress-title-tags/</link>
		<comments>http://digwp.com/2009/06/custom-wordpress-title-tags/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 23:03:33 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[header]]></category>
		<category><![CDATA[tags]]></category>
		<category><![CDATA[title]]></category>

		<guid isPermaLink="false">http://modernwordpress.com/?p=22</guid>
		<description><![CDATA[By default, WordPress provides a decent way of including &#60;title&#62; information for your posts, pages, and various archive views. Using WordPress&#8217; built-in template tag, &#8220;wp_title()&#8221;, we can specify several useful parameters, including: sep &#8211; a string value indicating the separator displayed before the title echo &#8211; a boolean value determining whether or not the title [...]]]></description>
			<content:encoded><![CDATA[<p>By default, WordPress provides a decent way of including <code>&lt;title&gt;</code> information for your posts, pages, and various archive views. Using WordPress&rsquo; built-in template tag, &ldquo;<code>wp_title()</code>&rdquo;, we can specify several useful parameters, including:</p>
<ul>
<li><code>sep</code> &ndash; a string value indicating the separator displayed before the title</li>
<li><code>echo</code> &ndash; a boolean value determining whether or not the title is displayed</li>
<li><code>seplocation</code> &ndash; specifies the position of sep string, either left or right of the title</li>
</ul>
<p>Here is the basic format for this tag:</p>
<pre><code>&lt;?php wp_title('sep', 'echo', 'seplocation'); ?&gt;</code></pre>
<p>..which is typically combined with the <code>bloginfo('name')</code> tag and used in the <code>header.php</code> file as follows:</p>
<pre><code>&lt;head&gt;
&lt;title&gt;&lt;?php wp_title(' | ', 'echo', 'right'); ?&gt;&lt;?php bloginfo('name'); ?&gt;
&lt;/head&gt;</code></pre>
<p><span id="more-22"></span></p>
<p>This would produce the following output for each of the following page types:</p>
<ul>
<li>The Home page &ndash; outputs the name of the site</li>
<li>Individual pages &ndash; page title | name of site</li>
<li>Single post views &ndash; post title | name of site</li>
<li>Archived post views &ndash; outputs the name of the site</li>
<li>Date-based archives &ndash; year and/or month | name of site</li>
<li>Category archives &ndash; category title | name of site</li>
<li>Author archives &ndash; public username | name of site</li>
<li>404 error pages &ndash; outputs the name of the site</li>
<li>Search results &ndash; outputs the name of the site</li>
<li>Tag archives &ndash; tag name | name of site</li>
</ul>
<p>For the average blog, this works fine; most pages include the title as well as the blog name, while those without specific page names simply output the name of the site instead. To go above and beyond, however, a little more preparation is needed. For example, rather than output only the blog name for search and tag pages, why not specify the exact tag or search term being displayed? And what about archive pages? We can customize those as well using the following code:</p>
<pre><code>&lt;title&gt;
&lt;?php
if (is_category()) {
	echo 'Category: '; wp_title(''); echo ' - ';

} elseif (function_exists('is_tag') &amp;&amp; is_tag()) {
	single_tag_title('Tag Archive for &amp;quot;'); echo '&amp;quot; - ';

} elseif (is_archive()) {
	wp_title(''); echo ' Archive - ';

} elseif (is_page()) {
	echo wp_title(''); echo ' - ';

} elseif (is_search()) {
	echo 'Search for &amp;quot;'.wp_specialchars($s).'&amp;quot; - ';

} elseif (!(is_404()) &amp;&amp; (is_single()) || (is_page())) {
	wp_title(''); echo ' - ';

} elseif (is_404()) {
	echo 'Not Found - ';

} bloginfo('name');
?&gt;
&lt;/title&gt;</code></pre>
<p>When used in place of the default WordPress <code>wp_title()</code> tag, this code will produce clear, informative page titles for tag, search, date, author and other archive views, as well as for the dreaded 404 page. Further, this code may be modified to elaborate the various page titles however you wish, and also may be enhanced further, as explained in our book, <a href="http://digwp.com/preorder/" title="Digging into WordPress">Digging into WordPress</a>.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/06/custom-wordpress-title-tags/">Permalink</a> | <a href="http://digwp.com/2009/06/custom-wordpress-title-tags/#comments">3 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/06/custom-wordpress-title-tags/&title=Custom WordPress Title Tags">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/header/" rel="tag">header</a>, <a href="http://digwp.com/tag/tags/" rel="tag">tags</a>, <a href="http://digwp.com/tag/title/" rel="tag">title</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/06/custom-wordpress-title-tags/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

