<?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; template</title>
	<atom:link href="http://digwp.com/tag/template/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Thu, 09 Feb 2012 19:03:45 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>WordPress Custom functions.php Template, Part 2</title>
		<link>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/</link>
		<comments>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/#comments</comments>
		<pubDate>Wed, 07 Apr 2010 16:13:36 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1811</guid>
		<description><![CDATA[In a recent post, we show you how to clean up and enhance the functionality of WordPress with a custom functions.php template. In that post, we explain how using a custom functions.php template can speed up development while optimizing many key aspects of WordPress. In this post, we deliver another prime collection of 15 custom [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent post, we show you how to clean up and enhance the functionality of WordPress with a <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">custom functions.php template</a>. In <em>that</em> post, we explain how using a custom <code>functions.php</code> template can speed up development while optimizing many key aspects of WordPress. In <em>this</em> post, we deliver another prime collection of <strong>15 custom functions to enhance your WordPress site</strong>. These functions provide all sorts of useful functionality, including stuff like:</p>
<ul>
<li>Callback function for a custom comments loop</li>
<li>Automatic content insertion in posts and feeds</li>
<li>Spam and delete links for comments when logged in</li>
<li>Buffer period before new posts are added to your feeds</li>
<li>Including an Admin link to the &ldquo;All-Settings&rdquo; page</li>
<li>Removing the version and generator information from your site and feed</li>
</ul>
<p>These new functions <em>extend</em> the functionality of our original <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/" title="WordPress functions.php Template with 15 Essential Custom Functions">functions.php template</a> with <strong>15 more useful functions</strong>. Not everything presented here is going to be necessary for <em>all</em> of your themes, so just grab what you need and add it your own custom <code>functions.php</code> file.</p>
<p><span id="more-1811"></span></p>
<blockquote><p>In this <acronym title="Digging into WordPress">DiW</acronym> article, we extend our original functions.php template with 15 more useful functions.</p></blockquote>
<p>As before, we&rsquo;ll first walk through each of the functions and then unify them into a working <code>functions.php</code> template. To use, just copy and paste the template code at the end of this article or <a href="#functions-download" title="Download the zipped template file">grab a copy of the zipped functions.php file</a> and enjoy a custom collection of functions that will help you <strong>optimize your development process</strong> while enhancing WordPress with some <strong>awesome new functionality</strong>.</p>
<h3>Insert custom content after each post</h3>
<p>If you look at the different things contained within a typical post, you will find many common and repetitive items, such as feed links, copyright information, and <a href="http://perishablepress.com/press/2008/11/23/fully-valid-seo-friendly-social-media-links-for-wordpress/" title="Fully Valid, SEO-Friendly Social Media Links for WordPress">social-media bookmarks</a>. While there&rsquo;s nothing wrong with inserting this content into your <code>single.php</code> template, it is sometimes easier to manage things from the <code>functions.php</code> file. For example, at <a href="http://perishablepress.com/" title="Digital Design and Dialogue">Perishable Press</a>, I include a brief copyright statement at the end of each post. By including the following code in my <code>functions.php</code> template, it&rsquo;s something that happens automatically:</p>
<pre><code>// add custom post content
function add_post_content($content) {
	if(!is_feed() &amp;&amp; !is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_content', 'add_post_content');</code></pre>
<p>The trick here is an old one, but it&rsquo;s extremely useful. By changing the line beginning with &ldquo;<code>$content.</code>&rdquo;, you can add just about any content you like.</p>
<h3>Insert custom content in your feeds</h3>
<p>Just as with the previous method, this function makes it possible to automatically add any content to your feeds. Yes, I know there are plugins that will <a href="http://planetozh.com/blog/my-projects/wordpress-plugin-better-feed-rss/" title="Wordpress Plugin : Better Feed">make your feed footers do backflips</a>, but for a simple copyright message or other info, I think it is easier and more efficient to simply toss a few lines into your custom <code>functions.php</code> template:</p>
<pre><code>// add custom feed content
function add_feed_content($content) {
	if(is_feed()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_feed_content');
add_filter('the_content', 'add_feed_content');</code></pre>
<p>As before, you can change the added content to whatever you want by editing the &ldquo;<code>$content</code>&rdquo; variable. Once in place, this will append a dynamic copyright message to each post in your feed. Note: if you happen to be adding the same content to your web pages (using the previous method) <em>and</em> your feeds (using this method), you may combine the two functions like so:</p>
<pre><code>// add custom content to feeds and posts
function add_custom_content($content) {
	if(!is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_custom_content');
add_filter('the_content', 'add_custom_content');</code></pre>
<p>Remember that if you use this combined function that you should remove or comment out both of the individual ones to avoid duplicate output. It will be included but commented out in the complete <code>functions.php</code> template file.</p>
<h3>Completely remove the version number from pages and feeds</h3>
<p>A commonly cited <a href="http://digwp.com/2009/07/remove-wordpress-version-number/" title="How to Remove the WordPress Version Number (The Right Way)">security measure for WordPress-powered sites</a> involves removing the automatically generated version number from appearing in the <code>&lt;head&gt;</code> section of your pages&rsquo; source code. This type of security technique is referred to as &ldquo;security through obscurity,&rdquo; and aims at hiding potentially sensitive information from a would-be attacker. Here&rsquo;s a function that does the job:</p>
<pre><code>// remove version info from head and feeds
function complete_version_removal() {
	return '';
}
add_filter('the_generator', 'complete_version_removal');</code></pre>
<p>This will remove your site&rsquo;s version and generator information from all of your pages and feeds, making it a little bit harder for the bad guys and a little bit safer for you and your visitors.</p>
<h3>Customize the admin footer message</h3>
<p>Customization is what makes your online experience something special. For your own sites and for your clients&rsquo; sites, it is nice to customize the generic admin footer message with something a little more useful, informative, and inspiring. This little gem makes it easy:</p>
<pre><code>// customize admin footer text
function custom_admin_footer() {
	echo '&lt;a href="http://monzilla.biz/"&gt;Website Design by Monzilla Media&lt;/a&gt;';
} 
add_filter('admin_footer_text', 'custom_admin_footer');</code></pre>
<p>Here, for the sake of example, we are including a link to my web-design company, but you can customize the content with just about anything you wish. If this were something I had to do manually for each site, I probably wouldn&rsquo;t do it. But by adding these few lines to my <code>functions.php</code> template, it all happens automatically, without me having to think about it. Nice&nbsp;;)</p>
<h3>Enable HTML markup in user profiles</h3>
<p>When customizing their profiles, users may want to include a hyperlink, bold text, or some other <acronym title="Hypertext markup language">HTML</acronym> markup. By default, WordPress prevents this from happening, but you can easily enable it with this friendly little snippet:</p>
<pre><code>// enable html markup in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');</code></pre>
<p><strong>Note:</strong> as <a href="#comment-4171" title="Jump to comment">miqrogroove</a> points out, enabling <acronym title="Hypertext markup language">HTML</acronym> may be best left to sites that have open user-registration disabled. Use with discretion.</p>
<h3>Delay feed update after posting</h3>
<p>As a chronic perfectionist, I hate it when I post something only to discover an error a few minutes later. By the time I notice, fix and update the post, it&rsquo;s already been beamed out all over the freakin&rsquo; place. To prevent this, I like to take the advice of <a href="http://wpengineer.com/publish-the-feed-later/" title="Publish The Feed Later">WPEngineer</a> and give myself a little buffer period or &ldquo;safety net&rdquo; after publishing my posts.</p>
<pre><code>// delay feed update
function publish_later_on_feed($where) {
	global $wpdb;

	if (is_feed()) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '5'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb-&gt;posts.post_date_gmt, '$now') &gt; $wait ";
	}
	return $where;
}
add_filter('posts_where', 'publish_later_on_feed');</code></pre>
<p>This code quietly and automatically gives me an extra five minutes before my post is added to my feeds. If you need more or less than five minutes, just edit the &ldquo;<code>$wait</code>&rdquo; variable with the integer of your choice.</p>
<h3>Add an Admin link to the WordPress &ldquo;All-Settings&rdquo; page</h3>
<p>As we&rsquo;ve explained before, WordPress makes it easy to <a href="http://digwp.com/2009/06/edit-your-database-options-from-the-wordpress-admin/" title="Edit Your Database Options from the WordPress Admin">view and edit your blog settings from the Admin area</a>. Thanks to a file named &ldquo;<code>options.php</code>&rdquo;, WordPress will display all of your database settings and enable you to edit a majority of them. To view this page, you need to log in as Admin and enter this <acronym title="Uniform Resource Locator">URL</acronym> in your browser&rsquo;s address bar:</p>
<p><code>http://domain.tld/wp-admin/options.php</code></p>
<p>Having access to your &ldquo;All-Settings&rdquo; page can be extremely helpful, so it&rsquo;s nice to display a direct link for easy access. The following slice of code in your <code>functions.php</code> file is all that&rsquo;s needed:</p>
<pre><code>// admin link for all settings
function all_settings_link() {
	add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');</code></pre>
<p>Once in place, you will see a link to your &ldquo;All Settings&rdquo; page in the WordPress Admin. You can change the name of the link to whatever you prefer by editing the two instances of &ldquo;All Settings&rdquo;.</p>
<h3>Remove all nofollow attributes from comments</h3>
<p>There are <a href="http://perishablepress.com/press/2007/09/23/much-ado-about-nofollow-the-perishable-press-dofollow-series/" title="Much ado about nofollow: The Perishable Press Dofollow Series">a million ways</a> to <a href="http://perishablepress.com/press/2007/09/05/comprehensive-reference-for-wordpress-no-nofollow-dofollow-plugins/" title="Comprehensive Reference for WordPress NoNofollow/Dofollow Plugins">remove nofollow</a> from your comments, but nothing is as <em>easy</em> as this method provided by code guru <a href="http://toscho.de/2009/no-no-no-nofollow/" title="No no no nofollow">Thomas Scholz</a>:</p>
<pre><code>// remove nofollow from comments
function xwp_dofollow($str) {
	$str = preg_replace(
		'~&lt;a ([^&gt;]*)\s*(["|\']{1}\w*)\s*nofollow([^&gt;]*)&gt;~U',
		'&lt;a ${1}${2}${3}&gt;', $str);
	return str_replace(array(' rel=""', " rel=''"), '', $str);
}
remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');</code></pre>
<p>That code will remove all instances of the nefarious &ldquo;<code>nofollow</code>&rdquo; attribute from <em>all</em> comment items, including the author link and comment text. This is a great way to automatically remove nofollow with no plugins or hacking required.</p>
<h3>Enable easy display of your post&rsquo;s word count</h3>
<p>This function enables you to display your post&rsquo;s word count without cluttering up the WordPress loop. To display the word count of your posts, first place this in your <code>functions.php</code> file:</p>
<pre><code>// count words in posts
function word_count() {
	global $post;
	echo str_word_count($post-&gt;post_content);
}</code></pre>
<p>Then, simply place this anywhere in your loop where you would like the number to appear:</p>
<p><code>&lt;?php word_count(); ?&gt;</code></p>
<p>So for example, you could display your post&rsquo;s word count to your visitors with something like:</p>
<p><code>&lt;p&gt;This post contains a whopping &lt;?php word_count(); ?&gt; words.&lt;/p&gt;</code></p>
<p>We can also easily display the word count of other items, such as the post title:</p>
<p><code>&lt;?php echo str_word_count($post-&gt;post_title); ?&gt;</code></p>
<p>Likewise, we can exclude the function from <code>functions.php</code> and get the word count with a single line of code in the loop:</p>
<p><code>&lt;?php echo str_word_count($post-&gt;post_content); ?&gt;</code></p>
<p>Just slap &lsquo;em anywhere in your post loop to display your word count. Not always needed, but nice to have available&nbsp;;)</p>
<h3>Enable delete and spam links for comments</h3>
<p>Managing your comments is easily done via the Admin, but geeks like me also like to see things from the outside, as they appear to the public. Browsing through comments as they appear on your site helps you catch things that may have eluded routine approvals in the Admin&rsquo;s comment listings. To help facilitate this process, I like to include a <a href="http://perishablepress.com/press/2008/12/01/spam-delete-buttons-links-for-old-versions-wordpress/" title="Backwards-Compatible Spam and Delete Buttons for WordPress">backwards-compatible set of spam and delete links</a> next to each comment. This makes it super-easy to cultivate comments live on the site.</p>
<pre><code>// spam &amp; delete links for all versions of wordpress
function delete_comment_link($id) {
	if (current_user_can('edit_post')) {
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;c='.$id.'"&gt;del&lt;/a&gt; ';
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;dt=spam&amp;c='.$id.'"&gt;spam&lt;/a&gt;';
	}
}</code></pre>
<p>Once this is included in your <code>functions.php</code> file, displaying the links is as easy as adding this to your comments loop:</p>
<pre><code>&lt;?php delete_comment_link(get_comment_ID()); ?&gt;</code></pre>
<h3>Disable all WordPress feeds</h3>
<p>Thanks to <a href="http://wpengineer.com/disable-wordpress-feed/" title="How to Disable RSS Feeds in WordPress">Frank from WPEngineer</a>, it is easy to disable all feed functionality for your site. Here is the <code>functions.php</code> code:</p>
<p><strong>Note:</strong> Only use this function if you want to <em>disable</em> your feeds! This function will be commented out of the complete <code>functions.php</code> file.</p>
<pre><code>// disable all feeds
function fb_disable_feed() {
	wp_die(__('&lt;h1&gt;Feed not available, please visit our &lt;a href="'.get_bloginfo('url').'"&gt;Home Page&lt;/a&gt;!&lt;/h1&gt;'));
}
add_action('do_feed',      'fb_disable_feed', 1);
add_action('do_feed_rdf',  'fb_disable_feed', 1);
add_action('do_feed_rss',  'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1);</code></pre>
<p>This function will quietly and completely disable all of your site&rsquo;s feeds, including all different formats. With this code in place, any request for your feed will return the following message in a nice, big set of <code>&lt;h1&gt;</code> tags:</p>
<blockquote><p>Feed not available, please visit our <a href="http://digwp.com/">Home Page</a>!</p></blockquote>
<p>This message is easily customized by editing the &ldquo;<code>wp_die</code>&rdquo; argument in the function.</p>
<h3>Customize the default gravatars and add your own</h3>
<p>Instead of suffering with the rather dull default gravatars, use this code to customize your own: </p>
<pre><code>// customize default gravatars
function custom_gravatars($avatar_defaults) {

	// change the default gravatar
	$customGravatar1 = get_bloginfo('template_directory').'/images/gravatar-01.png';
	$avatar_defaults[$customGravatar1] = 'Default';

	// add a custom user gravatar
	$customGravatar2 = get_bloginfo('template_directory').'/images/gravatar-02.png';
	$avatar_defaults[$customGravatar2] = 'Custom Gravatar';

	// add another custom gravatar
	$customGravatar3 = get_bloginfo('template_directory').'/images/gravatar-03.png';
	$avatar_defaults[$customGravatar3] = 'Custom gravatar';

	return $avatar_defaults;
}
add_filter('avatar_defaults', 'custom_gravatars');</code></pre>
<p>Of course, you can manually choose a default gravatar by specifying its location via the &ldquo;<code>get_avatar</code>&rdquo; template tag, but this method makes it <em>so</em> much easier. Not only does it replace the default with <em>multiple</em> custom gravatars, but it also goes the extra mile by displaying them in the WordPress Admin area under <strong>Settings &gt; Discussion</strong>. From there, you can select any of your custom gravatars by simply selecting it and clicking the &ldquo;Update&rdquo; button. Nothing could be easier. </p>
<p>A few notes about this function:</p>
<ul>
<li>As is, it adds three new gravatars to choose as defaults.</li>
<li>Each gravatar should be located in your theme&rsquo;s <code>images</code> directory.</li>
<li>You can add as many default gravatars as you would like by emulating the code pattern.</li>
<li>If you keep your custom gravatars someplace else, be sure and edit the image paths accordingly.</li>
</ul>
<h3>Disable automatic formatting in post content via shortcode</h3>
<p><a href="http://www.wprecipes.com/disable-wordpress-automatic-formatting-on-posts-using-a-shortcode" title="Disable WordPress automatic formatting on posts using a shortcode">WPRecipes</a> shows us how to prevent WordPress from automatically formatting chunks of post content by using a shortcode. This is very useful for posting code, poetry, or anything else that you would like to display in raw format. To do this, we add the following snippet to our <code>functions.php</code> file:</p>
<pre><code>// disable auto formatting in posts
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);</code></pre>
<p>With that code in place, you can insert unformatted code into your posts via the &ldquo;<code>[raw]</code>&rdquo; shortcode, for example:</p>
<p><code>[raw]Unformatted content[/raw]</code></p>
<p>Anything contained within those shortcodes will be left unformatted when displayed in your posts.</p>
<h3>Escape HTML entities in comments</h3>
<p><a href="http://konstruktors.com/blog/wordpress/1850-automatically-escape-html-entities-of-code-fragments-in-comments/" title="Automatically Escape HTML Entities of Code Fragments in Comments">Kaspars Dambis</a> shows us how to automatically escape encoded <acronym title="Hypertext markup Language">HTML</acronym> entities in the comments that readers leave on your posts. This is especially useful for blogs that deal in heavy code exchanges on post threads. This enables your commentators to simply wrap their code in <code>&lt;code&gt;</code> tags and not have to worry about manually converting characters such as angled brackets (&ldquo;<code>&lt;</code>&rdquo; &amp; &ldquo;<code>&gt;</code>&rdquo;) into their encoded equivalents (&ldquo;<code>&amp;lt;</code>&rdquo; &amp; &ldquo;<code>&amp;gt;</code>&rdquo;).</p>
<pre><code>// escape html entities in comments
function encode_code_in_comment($source) {
	$encoded = preg_replace_callback('/&lt;code&gt;(.*?)&lt;\/code&gt;/ims',
	create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
	return "&lt;code&gt;" . htmlentities($matches[1]) . "&lt;/"."code&gt;";'), $source);
	if ($encoded)
		return $encoded;
	else
		return $source;
}
add_filter('pre_comment_content', 'encode_code_in_comment');</code></pre>
<p>Once in place in your <code>functions.php</code> file, simply tell your commentators to wrap their code snippets in <code>&lt;code&gt;</code> tags. In other words, any content wrapped in <code>&lt;code&gt;</code> tags will be encoded automatically. Plus, in order to prevent unwanted <code>&lt;br</code>&nbsp;<code>/&gt;</code> tags, this function also automatically removes line breaks after the opening <code>&lt;code&gt;</code> tag and before the closing <code>&lt;code&gt;</code> tag.</p>
<h3>Custom comments display callback function</h3>
<p>When designing your theme&rsquo;s <code>comments.php</code> file, you can use either WordPress&rsquo; default code or create your own for full control over your comments display. If you&rsquo;re rolling your own, it is often easiest to grab a solid comments-display template and customize it to suit your needs. After many iterations and much refining, here is the comments callback function that I usually begin with:</p>
<pre><code>// custom comments callback function
function custom_comments_callback($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?&gt;

	&lt;li &lt;?php comment_class(); ?&gt; id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
		&lt;div class="comment-wrap"&gt;
			&lt;?php echo get_avatar(get_comment_author_email(), $size = '50', $default = bloginfo('stylesheet_directory').'/images/gravatar.png'); ?&gt;

			&lt;div class="comment-intro"&gt;
            			&lt;?php printf(__('%s'), get_comment_author_link()); ?&gt; &amp;ndash; &lt;a class="comment-permalink" href="&lt;?php echo htmlspecialchars(get_comment_link($comment-&gt;comment_ID)); ?&gt;"&gt;&lt;?php comment_date('F j, Y'); ?&gt; @ &lt;?php comment_time(); ?&gt;&lt;/a&gt;&lt;?php edit_comment_link('Edit', ' &amp;ndash; ', ''); ?&gt;
			&lt;/div&gt;
			&lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;

			&lt;p class="comment-moderation"&gt;&lt;?php _e('Your comment is awaiting moderation.'); ?&gt;&lt;/p&gt;
			&lt;?php endif; ?&gt;

			&lt;div class="comment-text"&gt;&lt;?php comment_text(); ?&gt;&lt;/div&gt;

			&lt;div class="reply" id="comment-reply-&lt;?php comment_ID(); ?&gt;"&gt;
				&lt;?php comment_reply_link(array_merge($args, array('reply_text'=&gt;'Reply', 'login_text'=&gt;'Log in to Reply', 'add_below'=&gt;'comment-reply', 'depth'=&gt;$depth, 'max_depth'=&gt;$args['max_depth']))); ?&gt; 

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

&lt;?php } // WP adds the closing &lt;/li&gt;</code></pre>
<p>There&rsquo;s a lot going on here, so let&rsquo;s highlight the important stuff:</p>
<ul>
<li><strong>Do not</strong> add the closing <code>&lt;/li&gt;</code> element &ndash; <a href="http://digwp.com/2010/02/custom-comments-html-output/" title="Custom Comments HTML Output">WordPress does this for you</a>.</li>
<li>This function calls for a default gravatar in your theme&rsquo;s &ldquo;<code>images</code>&rdquo; directory. Either ensure you&rsquo;ve got the required image in place or edit the code to reflect your site&rsquo;s reality.</li>
<li>Once this function is included in your <code>functions.php</code> file, you can display it by using the following comments loop in your <code>comments.php</code> file:</li>
</ul>
<pre><code>&lt;?php if (have_comments()) : ?&gt;
&lt;ol class="commentlist"&gt;
	&lt;?php wp_list_comments('type=comment&amp;style=ol&amp;callback=custom_comments_callback'); ?&gt;
&lt;/ol&gt;
&lt;?php else : ?&gt;</code></pre>
<p>Notice the third parameter for the <code>wp_list_comments</code> template tag? that&rsquo;s what makes it go. Also important is the &ldquo;<code>style=ol</code>&rdquo; parameter, which tells WordPress that we are using an ordered list for comments and that it should automatically close the markup with a <code>&lt;/li&gt;</code> element.</p>
<h3>Putting it all together..</h3>
<p>As promised, here is the full-meal deal &ndash; the entire collection neatly organized into a single chunk of code:</p>
<pre><code>&lt;?php // custom functions.php template @ digwp.com

// add custom post content
function add_post_content($content) {
	if(!is_feed() &amp;&amp; !is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_content', 'add_post_content');


// add custom feed content
function add_feed_content($content) {
	if(is_feed()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_feed_content');
add_filter('the_content', 'add_feed_content');


/* add custom content to feeds and posts
function add_custom_content($content) {
	if(!is_home()) {
		$content .= '&lt;p&gt;This article is copyright &amp;copy; '.date('Y').'&amp;nbsp;'.bloginfo('name').'&lt;/p&gt;';
	}
	return $content;
}
add_filter('the_excerpt_rss', 'add_custom_content');
add_filter('the_content', 'add_custom_content'); */


// remove version info from head and feeds
function complete_version_removal() {
	return '';
}
add_filter('the_generator', 'complete_version_removal');


// customize admin footer text
function custom_admin_footer() {
	echo '&lt;a href="http://monzilla.biz/"&gt;Website Design by Monzilla Media&lt;/a&gt;';
} 
add_filter('admin_footer_text', 'custom_admin_footer');


// enable html markup in user profiles
remove_filter('pre_user_description', 'wp_filter_kses');


// delay feed update
function publish_later_on_feed($where) {
	global $wpdb;

	if (is_feed()) {
		// timestamp in WP-format
		$now = gmdate('Y-m-d H:i:s');

		// value for wait; + device
		$wait = '5'; // integer

		// http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_timestampdiff
		$device = 'MINUTE'; // MINUTE, HOUR, DAY, WEEK, MONTH, YEAR

		// add SQL-sytax to default $where
		$where .= " AND TIMESTAMPDIFF($device, $wpdb-&gt;posts.post_date_gmt, '$now') &gt; $wait ";
	}
	return $where;
}
add_filter('posts_where', 'publish_later_on_feed');


// admin link for all settings
function all_settings_link() {
	add_options_page(__('All Settings'), __('All Settings'), 'administrator', 'options.php');
}
add_action('admin_menu', 'all_settings_link');


// remove nofollow from comments
function xwp_dofollow($str) {
	$str = preg_replace(
		'~&lt;a ([^&gt;]*)\s*(["|\']{1}\w*)\s*nofollow([^&gt;]*)&gt;~U',
		'&lt;a ${1}${2}${3}&gt;', $str);
	return str_replace(array(' rel=""', " rel=''"), '', $str);
}
remove_filter('pre_comment_content',     'wp_rel_nofollow');
add_filter   ('get_comment_author_link', 'xwp_dofollow');
add_filter   ('post_comments_link',      'xwp_dofollow');
add_filter   ('comment_reply_link',      'xwp_dofollow');
add_filter   ('comment_text',            'xwp_dofollow');


// count words in posts
function word_count() {
	global $post;
	echo str_word_count($post-&gt;post_content);
}


// spam &amp; delete links for all versions of wordpress
function delete_comment_link($id) {
	if (current_user_can('edit_post')) {
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;c='.$id.'"&gt;del&lt;/a&gt; ';
		echo '| &lt;a href="'.get_bloginfo('wpurl').'/wp-admin/comment.php?action=cdc&amp;dt=spam&amp;c='.$id.'"&gt;spam&lt;/a&gt;';
	}
}


/* disable all feeds
function fb_disable_feed() {
	wp_die(__('&lt;h1&gt;Feed not available, please visit our &lt;a href="'.get_bloginfo('url').'"&gt;Home Page&lt;/a&gt;!&lt;/h1&gt;'));
}
add_action('do_feed',      'fb_disable_feed', 1);
add_action('do_feed_rdf',  'fb_disable_feed', 1);
add_action('do_feed_rss',  'fb_disable_feed', 1);
add_action('do_feed_rss2', 'fb_disable_feed', 1);
add_action('do_feed_atom', 'fb_disable_feed', 1); */


// customize default gravatars
function custom_gravatars($avatar_defaults) {

	// change the default gravatar
	$customGravatar1 = get_bloginfo('template_directory').'/images/gravatar-01.png';
	$avatar_defaults[$customGravatar1] = 'Default';

	// add a custom user gravatar
	$customGravatar2 = get_bloginfo('template_directory').'/images/gravatar-02.png';
	$avatar_defaults[$customGravatar2] = 'Custom Gravatar';

	// add another custom gravatar
	$customGravatar3 = get_bloginfo('template_directory').'/images/gravatar-03.png';
	$avatar_defaults[$customGravatar3] = 'Custom gravatar';

	return $avatar_defaults;
}
add_filter('avatar_defaults', 'custom_gravatars');


// disable auto formatting in posts
function my_formatter($content) {
	$new_content = '';
	$pattern_full = '{(\[raw\].*?\[/raw\])}is';
	$pattern_contents = '{\[raw\](.*?)\[/raw\]}is';
	$pieces = preg_split($pattern_full, $content, -1, PREG_SPLIT_DELIM_CAPTURE);

	foreach ($pieces as $piece) {
		if (preg_match($pattern_contents, $piece, $matches)) {
			$new_content .= $matches[1];
		} else {
			$new_content .= wptexturize(wpautop($piece));
		}
	}

	return $new_content;
}
remove_filter('the_content', 'wpautop');
remove_filter('the_content', 'wptexturize');
add_filter('the_content', 'my_formatter', 99);


// escape html entities in comments
function encode_code_in_comment($source) {
	$encoded = preg_replace_callback('/&lt;code&gt;(.*?)&lt;\/code&gt;/ims',
	create_function('$matches', '$matches[1] = preg_replace(array("/^[\r|\n]+/i", "/[\r|\n]+$/i"), "", $matches[1]); 
	return "&lt;code&gt;" . htmlentities($matches[1]) . "&lt;/"."code&gt;";'), $source);
	if ($encoded)
		return $encoded;
	else
		return $source;
}
add_filter('pre_comment_content', 'encode_code_in_comment');


// custom comments callback function
function custom_comments_callback($comment, $args, $depth) {
	$GLOBALS['comment'] = $comment; ?&gt;

	&lt;li &lt;?php comment_class(); ?&gt; id="comment-&lt;?php comment_ID(); ?&gt;"&gt;
		&lt;div class="comment-wrap"&gt;
			&lt;?php echo get_avatar(get_comment_author_email(), $size = '50', $default = bloginfo('stylesheet_directory').'/images/gravatar.png'); ?&gt;

			&lt;div class="comment-intro"&gt;
            			&lt;?php printf(__('%s'), get_comment_author_link()); ?&gt; &amp;ndash; &lt;a class="comment-permalink" href="&lt;?php echo htmlspecialchars(get_comment_link($comment-&gt;comment_ID)); ?&gt;"&gt;&lt;?php comment_date('F j, Y'); ?&gt; @ &lt;?php comment_time(); ?&gt;&lt;/a&gt;&lt;?php edit_comment_link('Edit', ' &amp;ndash; ', ''); ?&gt;
			&lt;/div&gt;
			&lt;?php if ($comment-&gt;comment_approved == '0') : ?&gt;

			&lt;p class="comment-moderation"&gt;&lt;?php _e('Your comment is awaiting moderation.'); ?&gt;&lt;/p&gt;
			&lt;?php endif; ?&gt;

			&lt;div class="comment-text"&gt;&lt;?php comment_text(); ?&gt;&lt;/div&gt;

			&lt;div class="reply" id="comment-reply-&lt;?php comment_ID(); ?&gt;"&gt;
				&lt;?php comment_reply_link(array_merge($args, array('reply_text'=&gt;'Reply', 'login_text'=&gt;'Log in to Reply', 'add_below'=&gt;'comment-reply', 'depth'=&gt;$depth, 'max_depth'=&gt;$args['max_depth']))); ?&gt; 

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

&lt;?php } // WP adds the closing &lt;/li&gt;

?&gt;</code></pre>
<h3 id="functions-download">Download the custom functions.php template file</h3>
<p>If you prefer, you can download this code in a ready-to-go <code>functions.php</code> file in zipped format:</p>
<h4><a href="http://digwp.com/plugins/custom-functions-template-2.zip">Download zipped functions.php Template File</a></h4>
<h3>Also..</h3>
<p>If this post is useful to <acronym title="Digging into WordPress">DiW</acronym> readers, I’ll be writing up yet another article (part 3!) with even more useful custom functions. If that happens, the third set of functions will include some slightly more advanced techniques. <a href="http://feeds2.feedburner.com/DiggingIntoWordpress" title="Grab the Feed!">Stay tuned</a>!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/">Permalink</a> | <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/#comments">17 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/&title=WordPress Custom functions.php Template, Part 2">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/feed/</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>WordPress functions.php Template with 15 Essential Custom Functions</title>
		<link>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/</link>
		<comments>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/#comments</comments>
		<pubDate>Mon, 22 Mar 2010 06:25:58 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1699</guid>
		<description><![CDATA[When designing WordPress themes, I always add a common set of custom functions to the theme&#8217;s functions.php file. This speeds up development time because I don&#8217;t have to hunt for and individually copy the same slew of functions for every theme. I just drop in a copy of my functions.php template and build up from [...]]]></description>
			<content:encoded><![CDATA[<p>When designing WordPress themes, I always add <strong>a common set of custom functions</strong> to the theme&rsquo;s <code>functions.php</code> file. This speeds up development time because I don&rsquo;t have to hunt for and individually copy the same slew of functions for <em>every</em> theme. I just drop in a copy of my <strong>functions.php template</strong> and build up from there. This takes care of all those little things that always need to be done:</p>
<ul>
<li>Include jQuery</li>
<li>Enable threaded comments</li>
<li>Add feed links to the header</li>
<li>Disable unused widget areas</li>
<li>Adding Google Analytics to the footer</li>
<li>Stop the &ldquo;Read More&rdquo; link from jumping to the middle of the next page&nbsp;;)</li>
</ul>
<p>One of the things that I like about these functions is that they&rsquo;re all so concise, simple, and effective. The <code>functions.php</code> template file currently contains 15 different functions and is a continual work in progress. Not everyone is going to need or use everything in the file, but the idea is to modify this template into something that works for you. It&rsquo;s a starting point with some really useful functions.</p>
<p><span id="more-1699"></span></p>
<p>In this <acronym title="Digging into WordPress">DiW</acronym> article, we first provide an explanation of each of the 15 functions and then bring them all together into the working <code>functions.php</code> template. Just copy and paste the template code at the end of this article or <a href="#functions-download" title="Download the zipped template file">grab a copy of the zipped <code>functions.php</code> file</a> and enjoy a custom collection of functions that will help you optimize your development process while enhancing WordPress with essential functionality.</p>
<h3>Add feed links to header</h3>
<p>Since version 2.8, WordPress can add all relevant feed links (main, comments, categories, et al) to your <code>&lt;head&gt;</code> area. It doesn&rsquo;t happen by default, however, because you have to add the following snippet to make it work:</p>
<pre><code>// add feed links to header
if (function_exists('automatic_feed_links')) {
	automatic_feed_links();
} else {
	return;
}</code></pre>
<p>This will check to see if you&rsquo;re using a version of WordPress that is compatible, and then enable the automatic feed links. A couple of notes: first, this method assumes that you are not manually including any feed links in your <code>&lt;head&gt;</code>. Also, I read a <a href="http://core.trac.wordpress.org/ticket/12364" title="Deprecate automatic_feed_links() in favor of add_theme_support()">recent Trac ticket</a> that looked like this functionality was being integrated with <code>add_theme_support</code>, so keep your eyes open for that.</p>
<h3>Automatic jQuery inclusion</h3>
<p>We&rsquo;ve discussed <a href="http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/" title="Including jQuery in WordPress (The Right Way)">how to include jQuery the right way</a> by placing a little snippet in your document head, but here is a way to do it from your theme&rsquo;s <code>functions.php</code> file:</p>
<pre><code>// smart jquery inclusion
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false);
	wp_enqueue_script('jquery');
}</code></pre>
<p>This code ensures that only one copy of jQuery is included, and calls it from Google&rsquo;s servers to save bandwidth and take advantage of any primed caches that happen to be visiting. Note that this function needs to be located <em>before</em> the threaded-comments function in order for it to work.</p>
<h3>Enable threaded comments</h3>
<p>As we explain in <a href="http://digwp.com/book/" title="Get the Book!">the book</a>, enabling threaded comments requires adding a snippet of code into your <code>&lt;head&gt;</code> area just before the <code>wp_head</code> tag. After a little experimenting, I discovered that you can include this snippet from the <code>functions.php</code> file:</p>
<pre><code>// enable threaded comments
function enable_threaded_comments(){
	if (!is_admin()) {
		if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
			wp_enqueue_script('comment-reply');
		}
}
add_action('get_header', 'enable_threaded_comments');</code></pre>
<p>This helps keep your document <code>&lt;head&gt;</code> a little cleaner. Note that this function needs to be located <em>after</em> the jQuery-inclusion function in order for it to work.</p>
<p>Thanks to <a href="http://soupgiant.com/">Peter Wilson</a> for this <a href="http://bigredtin.com/wordpress/including-wordpress-comment-reply-js/" title="Including WordPress' comment-reply.js (the right way)">awesome technique</a>!</p>
<h3>Remove unwanted crap from the head section</h3>
<p>As we&rsquo;ve <a href="http://digwp.com/2009/07/remove-wordpress-version-number/" title="How to Remove the WordPress Version Number (The Right Way)">mentioned before</a>, WordPress spits out a <em>ton</em> of crap in the document <code>&lt;head&gt;</code> &ndash; stuff like the version number and <acronym title="Windows Live Writer">WLW</acronym>, <acronym title="Really Simple Discovery">RSD</acronym>, and index links. To clean things up, we add this nice little snippet into the <code>functions.php</code> template:</p>
<pre><code>// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);</code></pre>
<h3>Add Google Analytics to the footer</h3>
<p>Another annoying task that has to be done for all of the sites I create is adding Google Analytics code to the <code>footer.php</code> file. Recently it occurred to me to just add the code to my <code>functions.php</code> and never worry about it again:</p>
<pre><code>// add google analytics to footer
function add_google_analytics() {
	echo '&lt;script src="http://www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;';
	echo '&lt;script type="text/javascript"&gt;';
	echo 'var pageTracker = _gat._getTracker("UA-XXXXX-X");';
	echo 'pageTracker._trackPageview();';
	echo '&lt;/script&gt;';
}
add_action('wp_footer', 'add_google_analytics');</code></pre>
<p>A couple of notes here: first, obviously you want to replace the &ldquo;<code>UA-123456-1</code>&rdquo; with your actual <acronym title="Google Analytics">GA</acronym> code. Second, you may want to check out the <a href="http://perishablepress.com/press/2010/01/24/3-ways-track-google-analytics/" title="3 Ways to Track Web Pages with Google Analytics">three currently available Analytics options</a> and modify the code accordingly. Currently, this function is using the newer &ldquo;<code>ga.js</code>&rdquo; tracking code, but that is easily changed to either of the other methods.</p>
<h3>Custom excerpt length</h3>
<p>Instead of using the default 55-word limit, this function enables you to specify any length for your excerpts.</p>
<pre><code>// custom excerpt length
function custom_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'custom_excerpt_length');</code></pre>
<p>Just set your preferred number of words by editing the &ldquo;<code>20</code>&rdquo; to whatever you wish.</p>
<h3>Custom excerpt &ldquo;continue&rdquo; string</h3>
<p>Or whatever they call that funky bracketed ellipses thing &ldquo;<code>[...]</code>&rdquo; that is appended to your post excerpts by default. I like to remove the brackets, but with this <code>functions.php</code> snippet you can change it to anything:</p>
<pre><code>// custom excerpt ellipses for 2.9+
function custom_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'custom_excerpt_more');

/* custom excerpt ellipses for 2.8-
function custom_excerpt_more($excerpt) {
	return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'custom_excerpt_more'); 
*/</code></pre>
<p>As you can see, there are two different versions of this code, depending on your version of WordPress. We like to stay current, so we commented out the older method but left it there in case you need it. For either version of this technique, just replace the &ldquo;<code>...</code>&rdquo; with &ldquo;pants on the ground&rdquo; or whatever happens to suit your needs.</p>
<h3>No &ldquo;more&rdquo; jumping for the &ldquo;read more&rdquo; link</h3>
<p>One of the weirdest things that WordPress does is &ldquo;jump&rdquo; the reader to the location of the &ldquo;<code>&lt;!--</code><code>more--&gt;</code>&rdquo; tag on the single-post-view when the &ldquo;read more&rdquo; link is clicked. It&rsquo;s just awkward &#8212; if the jump was on the <em>same</em> page, it would make sense, but to load a new page and then take the reader halfway down without explaining anything is just wrong. In any case, here is a nice little function that will stop the jumping once and for all:</p>
<pre><code>// no more jumping for read more link
function no_more_jumping($post) {
	return '&lt;a href="'.get_permalink($post-&gt;ID).'" class="read-more"&gt;'.'Continue Reading'.'&lt;/a&gt;';
}
add_filter('excerpt_more', 'no_more_jumping');
add_filter('the_content_more_link', 'remove_more_jump_link');</code></pre>
<p>Nothing else needs to be done for this to work &ndash; just plug it in and enjoy your new &ldquo;jumpless&rdquo; functionality. Note that this is also a convenient place to customize the &ldquo;read more&rdquo; link with whatever attributes or custom text you wish.</p>
<h3>Add a favicon to your blog</h3>
<p>You just <em>gotsta</em> have a favicon for your blog, and this code makes it super easy to do. Just create your image and upload to site&rsquo;s root directory. The following code in your <code>functions.php</code> file makes it so by adding the required line to your <code>&lt;head&gt;</code> area:</p>
<pre><code>// add a favicon to your 
function blog_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" /&gt;';
}
add_action('wp_head', 'blog_favicon');</code></pre>
<p>Feel free to change the directory to whatever you desire. Also make sure that the <code>wp_head</code> is present within your theme&rsquo;s <code>header.php</code> file.</p>
<h3>Add a different favicon for your blog&rsquo;s Admin area</h3>
<p>While we&rsquo;re here, let&rsquo;s add a unique favicon to our Admin pages, so that they are easier to recognize when bookmarked or working with tabs. Just create a favicon and upload to your theme&rsquo;s <code>/images/</code> directory. This code takes care of the rest:</p>
<pre><code>// add a favicon for your admin
function admin_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.png" /&gt;';
}
add_action('admin_head', 'admin_favicon');</code></pre>
<p>As before, feel free to change the directory to whatever you desire. It might be best to keep your admin favicon in a separate directory than your blog favicon. Just sayin&rsquo;.</p>
<h3>Custom Admin Login logo</h3>
<p>You know that snazzy blue WordPress logo that is branding your various login pages? Yeh, you can change that to whatever you want. Just create your custom login image, name it &ldquo;<code>custom-login-logo.png</code>&rdquo;, and upload it to your theme&rsquo;s <code>/images/</code> directory. This code will take care of the rest:</p>
<pre><code>// custom admin login logo
function custom_login_logo() {
	echo '&lt;style type="text/css"&gt;
	h1 a { background-image: url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
	&lt;/style&gt;';
}
add_action('login_head', 'custom_login_logo');</code></pre>
<p>The key here is to make sure that the path and image names match that of your setup. Also, when creating your image, you may want to keep in mind the properties of the original: 30px length, 31px height, transparent <acronym title="Graphic Interchange Format">GIF</acronym> format, and header background color of #464646 (for the image matte).</p>
<h3>Disable unused widget areas</h3>
<p><a href="http://justintadlock.com/archives/2009/03/06/disable-widget-areas-without-touching-theme-templates" title="Disable widget areas (sidebars) without touching theme templates">Justin Tadlock</a> shares this handy function for removing unwanted widget areas from our theme &ndash; a <em>must</em> for customizing  existing themes:</p>
<pre><code>// disable all widget areas
function disable_all_widgets($sidebars_widgets) {
	//if (is_home())
		$sidebars_widgets = array(false);
	return $sidebars_widgets;
}
add_filter('sidebars_widgets', 'disable_all_widgets');</code></pre>
<p>This code is plug-&amp;-play &ndash; no other modifications need to be made. Note: if you only want to disable widgets on your Home page, then remove the two comment slashes (&ldquo;<code>//</code>&rdquo;) from the third line.</p>
<h3>Kill the WordPress update nag</h3>
<p>This is one of my favorites, but I know it&rsquo;s not for everyone. In any case, you know that &ldquo;Please update now..&rdquo; message that appears on every page in the WordPress Admin when new versions are available? This sweet little function kills it dead (or disables it, actually):</p>
<pre><code>// kill the admin nag
if (!current_user_can('edit_users')) {
	add_action('init', create_function('$a', "remove_action('init', 'wp_version_check');"), 2);
	add_filter('pre_option_update_core', create_function('$a', "return null;"));
}</code></pre>
<p>Feel free to comment this one out or remove it if you rely on the Admin nag to keep you informed of changes.</p>
<h3>Include category ID in body_class and post_class</h3>
<p>By default, WordPress <code>body_class</code> and <code>post_class</code> do not include the ID of the category of the current post. This custom function changes all that:</p>
<pre><code>// category id in body and post class
function category_id_class($classes) {
	global $post;
	foreach((get_the_category($post-&gt;ID)) as $category)
		$classes [] = 'cat-' . $category-&gt;cat_ID . '-id';
		return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');</code></pre>
<p>Even if you aren&rsquo;t using it, it&rsquo;s a nice function to have around, which is why it&rsquo;s included here for this custom <code>functions.php</code> template of essential functions. Keywords in the house because we can.</p>
<h3>Get the first category ID</h3>
<p>Another useful function when working with different categories is the ability to get the first category ID of the current post. This function makes it happen:</p>
<pre><code>// get the first category id
function get_first_category_ID() {
	$category = get_the_category();
	return $category[0]-&gt;cat_ID;
}</code></pre>
<p>Strictly plug-&amp;-play: just use <code>&lt;?php get_first_category_ID(); ?&gt;</code> in your theme template file to access the data.</p>
<h3>Putting it all together..</h3>
<p>As promised, here is the full-meal deal &ndash; the entire collection neatly organized into a single chunk of code:</p>
<pre><code>&lt;?php // custom functions.php template @ digwp.com

// add feed links to header
if (function_exists('automatic_feed_links')) {
	automatic_feed_links();
} else {
	return;
}


// smart jquery inclusion
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"), false, '1.3.2');
	wp_enqueue_script('jquery');
}


// enable threaded comments
function enable_threaded_comments(){
	if (!is_admin()) {
		if (is_singular() AND comments_open() AND (get_option('thread_comments') == 1))
			wp_enqueue_script('comment-reply');
		}
}
add_action('get_header', 'enable_threaded_comments');


// remove junk from head
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);


// add google analytics to footer
function add_google_analytics() {
	echo '&lt;script src="http://www.google-analytics.com/ga.js" type="text/javascript"&gt;&lt;/script&gt;';
	echo '&lt;script type="text/javascript"&gt;';
	echo 'var pageTracker = _gat._getTracker("UA-XXXXX-X");';
	echo 'pageTracker._trackPageview();';
	echo '&lt;/script&gt;';
}
add_action('wp_footer', 'add_google_analytics');


// custom excerpt length
function custom_excerpt_length($length) {
	return 20;
}
add_filter('excerpt_length', 'custom_excerpt_length');


// custom excerpt ellipses for 2.9+
function custom_excerpt_more($more) {
	return '...';
}
add_filter('excerpt_more', 'custom_excerpt_more');

/* custom excerpt ellipses for 2.8-
function custom_excerpt_more($excerpt) {
	return str_replace('[...]', '...', $excerpt);
}
add_filter('wp_trim_excerpt', 'custom_excerpt_more'); 
*/


// no more jumping for read more link
function no_more_jumping($post) {
	return '&lt;a href="'.get_permalink($post-&gt;ID).'" class="read-more"&gt;'.'Continue Reading'.'&lt;/a&gt;';
}
add_filter('excerpt_more', 'no_more_jumping');


// add a favicon to your 
function blog_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('wpurl').'/favicon.ico" /&gt;';
}
add_action('wp_head', 'blog_favicon');


// add a favicon for your admin
function admin_favicon() {
	echo '&lt;link rel="Shortcut Icon" type="image/x-icon" href="'.get_bloginfo('stylesheet_directory').'/images/favicon.png" /&gt;';
}
add_action('admin_head', 'admin_favicon');


// custom admin login logo
function custom_login_logo() {
	echo '&lt;style type="text/css"&gt;
	h1 a { background-image: url('.get_bloginfo('template_directory').'/images/custom-login-logo.png) !important; }
	&lt;/style&gt;';
}
add_action('login_head', 'custom_login_logo');


// disable all widget areas
function disable_all_widgets($sidebars_widgets) {
	//if (is_home())
		$sidebars_widgets = array(false);
	return $sidebars_widgets;
}
add_filter('sidebars_widgets', 'disable_all_widgets');


// kill the admin nag
if (!current_user_can('edit_users')) {
	add_action('init', create_function('$a', "remove_action('init', 'wp_version_check');"), 2);
	add_filter('pre_option_update_core', create_function('$a', "return null;"));
}


// category id in body and post class
function category_id_class($classes) {
	global $post;
	foreach((get_the_category($post-&gt;ID)) as $category)
		$classes [] = 'cat-' . $category-&gt;cat_ID . '-id';
		return $classes;
}
add_filter('post_class', 'category_id_class');
add_filter('body_class', 'category_id_class');


// get the first category id
function get_first_category_ID() {
	$category = get_the_category();
	return $category[0]-&gt;cat_ID;
}

?&gt;</code></pre>
<h3 id="functions-download">Download the custom functions.php template file</h3>
<p>If you prefer, you can download this code in a ready-to-go <code>functions.php</code> file in zipped format:</p>
<h4><a href="http://digwp.com/plugins/custom-functions-template.zip">Download zipped functions.php Template File</a></h4>
<h3>Also..</h3>
<p>If this post is useful to <acronym title="Digging into WordPress">DiW</acronym> readers, I&rsquo;ll be writing up another article (part 2) with even more useful custom functions. If that happens, the second set of functions will include some slightly more advanced techniques as opposed to these &ldquo;must-have&rdquo; template functions. <a href="http://feeds2.feedburner.com/DiggingIntoWordpress" title="Grab the Feed!">Stay tuned</a>! <strong>Update:</strong> <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/" title="WordPress Custom functions.php Template, Part 2">Custom functions.php Part 2 is here</a>!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/">Permalink</a> | <a href="http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/#comments">80 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/&title=WordPress functions.php Template with 15 Essential Custom Functions">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/wordpress-functions-php-template-custom-functions/feed/</wfw:commentRss>
		<slash:comments>80</slash:comments>
		</item>
		<item>
		<title>Which Template File does WordPress Use to Render Different Pages?</title>
		<link>http://digwp.com/2010/02/template-heirarchy-chart/</link>
		<comments>http://digwp.com/2010/02/template-heirarchy-chart/#comments</comments>
		<pubDate>Fri, 19 Feb 2010 14:34:51 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1431</guid>
		<description><![CDATA[This page in the codex has a particularly interesting infographic that shows a flowchart of how WordPress chooses which template file it is going to use to render the page. For example, did you know if you have a published page with &#8220;contact&#8221; as the slug, it will look for and use page-contact.php automatically? Unfortunately [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://codex.wordpress.org/Template_Hierarchy">This page</a> in the codex has a particularly interesting infographic that shows a flowchart of how WordPress chooses which template file it is going to use to render the page. For example, did you know if you have a published page with &#8220;contact&#8221; as the slug, it will look for and use page-contact.php automatically?</p>
<p>Unfortunately this graphic wasn&#8217;t very pretty and for some reason has a giant &#8220;Page 1&#8243; text awkward sitting over it. We have an outdated version of this in the book, and since we are updating it right now, I thought I would take the opportunity to re-create this chart.</p>
<p><span id="more-1431"></span></p>
<p><a href="http://digwp.com/wp-content/blog-images/whichtemplate-large.png">CLICK FOR FULL SIZE VERSION</a><br />
<a href="http://digwp.com/wp-content/blog-images/whichtemplate-large.png"><img src="http://digwp.com/wp-content/blog-images/whichtemplate-small.png" width="590" height="472" alt="" title="" /></a></p>
<p>This will also be used in the <a href="http://digwp.com/book/">book</a>, which should be back available for order in around a week or so! Stay tuned!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/template-heirarchy-chart/">Permalink</a> | <a href="http://digwp.com/2010/02/template-heirarchy-chart/#comments">12 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/02/template-heirarchy-chart/&title=Which Template File does WordPress Use to Render Different Pages?">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/template-heirarchy-chart/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Two Ways to Limit the Number of Posts without a Plugin</title>
		<link>http://digwp.com/2009/12/limit-posts-without-plugin/</link>
		<comments>http://digwp.com/2009/12/limit-posts-without-plugin/#comments</comments>
		<pubDate>Thu, 10 Dec 2009 13:27:10 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1046</guid>
		<description><![CDATA[Let&#8217;s say your blog is set to display ten posts per page, as specified via the WordPress Admin under Settings &#62; Reading. Once set, ten posts will appear on your home page, archive pages, search results, and so on. In other words, if it isn&#8217;t a single-view page or an actual &#8220;page&#8221; page, you&#8217;re gonna [...]]]></description>
			<content:encoded><![CDATA[<p>Let&rsquo;s say your blog is set to display ten posts per page, as specified via the WordPress Admin under <strong>Settings &gt; Reading</strong>. Once set, ten posts will appear on your home page, archive pages, search results, and so on. In other words, if it isn&rsquo;t a single-view page or an actual &ldquo;page&rdquo; page, you&rsquo;re gonna get ten posts per page. It&rsquo;s a <em>global</em> setting.</p>
<p>But what if you want to display different numbers of posts for different types of page views? For example, instead of showing just ten posts on your search-results pages, you may want to show a whole bunch, like maybe fifty or something. Perhaps you would also like to <em>limit</em> the number of posts displayed on your category archives to only five. Of course, many of us know the <em>easy</em> way to do this: install <a href="http://moshublog.com/2007/10/30/custom-query-string-reloaded-for-wordpress-23-with-tag-support/" title="Custom Query String Reloaded">Custom Query String</a> or <a href="http://coffee2code.com/wp-plugins/custom-post-limits/" title="Custom Post Limits">Custom Post Limits</a>, tweak a few settings, and call it good. But.. this <em>does</em> require commitment to yet another plugin, which is a good reason for doing things the &ldquo;hard&rdquo; way..</p>
<p><span id="more-1046"></span></p>
<h3>Method 1</h3>
<p>Fortunately, we can account for the latter scenario <em>without</em> relying on a plugin. Normally, the loop controls the number of posts displayed via the <code>while(have_posts())</code> condition, as shown in this extremely boring example of a typical loop:</p>
<pre><code>&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

	&lt;h1&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt;
	&lt;p&gt;?php the_time(); ?&gt;&lt;/p&gt;
	&lt;?php the_content(); ?&gt;
	&lt;p&gt;&lt;?php the_tags(); ?&gt;&lt;/p&gt;

&lt;?php endwhile;?&gt;

	&lt;p&gt;&lt;?php next_posts_link(); ?&gt;&lt;/p&gt;
	&lt;p&gt;&lt;?php previous_posts_link(); ?&gt;&lt;/p&gt;

&lt;?php else : ?&gt;

	&lt;h1&gt;Not Found&lt;/h1&gt;
	&lt;p&gt;Silly monkey.&lt;/p&gt;

&lt;?php endif; ?&gt;</code></pre>
<p>What&rsquo;s happening here is that we are running the loop <strong>only&nbsp;if</strong> we <em>have</em> posts, and only <strong>while</strong> the number of posts is <em>less than or equal to</em> the amount specified in the Admin area. Thus, limiting the number of posts is simply a matter of replacing &ldquo;<code>while(have_posts())</code>&rdquo; with something more restrictive.</p>
<p>There are probably a zillion ways of doing this, but the easiest that I have found is to simply setup a counter variable to keep track of each iteration of the loop. Once the counter variable reaches the specified value, the loop stops. Here&rsquo;s the previous example loop showing the required modifications:</p>
<pre><code>&lt;?php $i = 1; while (have_posts() &amp;&amp; $i &lt; 6) : the_post(); ?&gt;

	&lt;h1&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt;
	&lt;p&gt;?php the_time(); ?&gt;&lt;/p&gt;
	&lt;?php the_content(); ?&gt;
	&lt;p&gt;&lt;?php the_tags(); ?&gt;&lt;/p&gt;

&lt;?php $i++; endwhile; ?&gt;

	&lt;p&gt;&lt;?php next_posts_link(); ?&gt;&lt;/p&gt;
	&lt;p&gt;&lt;?php previous_posts_link(); ?&gt;&lt;/p&gt;

&lt;?php else : ?&gt;

	&lt;h1&gt;Not Found&lt;/h1&gt;
	&lt;p&gt;Silly monkey.&lt;/p&gt;

&lt;?php endif; ?&gt;</code></pre>
<p>Notice that in the first line we are initiating the counter variable &ldquo;<code>$i</code>&rdquo; and then setting its limit at &ldquo;<code>6</code>&rdquo;. We also add &ldquo;<code>$i++;</code>&rdquo; before the &ldquo;<code>endwhile</code>&rdquo; statement to increase the count by one for each iteration of the loop. The result of these modifications is that the loop will now run only five times (as specified in the first line) instead of ten times (as specified in the WordPress Admin).</p>
<p>Just keep in mind that this trick only works when you want to <em>limit</em> the total number of posts displayed on a particular page. Even so, it is still possible to avoid a plugin by setting your default post display to something high, like 20 or 30. Then, your blog displays the highest number of posts where you want them, and everything less is customized by limiting this default number with a couple lines of code. This technique could also be useful for designing themes that required a specific number of posts displayed in certain areas of the blog.</p>
<h3>Method 2</h3>
<p><strong>Or</strong>, you could just use <code>query_posts</code> to create a custom query and specify the <code>showposts</code> parameter with a value of &ldquo;<code>5</code>&rdquo; (or whatever number you wish). Here is what our original loop example looks like using the <code>query_posts</code> function:</p>
<pre><code>&lt;?php query_posts('showposts=5'); if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

	&lt;h1&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h1&gt;
	&lt;p&gt;?php the_time(); ?&gt;&lt;/p&gt;
	&lt;?php the_content(); ?&gt;
	&lt;p&gt;&lt;?php the_tags(); ?&gt;&lt;/p&gt;

&lt;?php endwhile;?&gt;

	&lt;p&gt;&lt;?php next_posts_link(); ?&gt;&lt;/p&gt;
	&lt;p&gt;&lt;?php previous_posts_link(); ?&gt;&lt;/p&gt;

&lt;?php else : ?&gt;

	&lt;h1&gt;Not Found&lt;/h1&gt;
	&lt;p&gt;Silly monkey.&lt;/p&gt;

&lt;?php endif; wp_reset_query(); ?&gt;</code></pre>
<p>Notice the two additions to the original loop: in the first line, we added the <code>query_posts</code> function with the required <code>posts_per_page</code> parameter set to <code>5</code>. Then, in the last line, we invoke the mystical powers of <code>wp_reset_query</code> to reset the original posts query. Resetting the query ensures that it&rsquo;s available elsewhere in the template and is just good practice in general when using <code>query_posts</code>. </p>
<p>The <strong>pros</strong> of using <code>query_posts</code> to modify the number of posts is that you can go either way &#8212; you can either <em>decrease</em> or <em>increase</em> the total number of posts displayed on any page &#8212; no plugins necessary.</p>
<p>The <strong>cons</strong> of using the <code>query_posts</code> method mainly involve the disruption of the original <code>wp_query</code> object normally used to communicate parameters involving page, category, search, and other properties to the <acronym title="Structured Query Language">SQL</acronym> query*. Avoiding this drama is one of the reasons why using a simple counter variable (as described in the first half of the post) is often the preferred method (multiple loops, anyone?).</p>
<p>*<strong>Note:</strong> It <em>is</em> possible to include this default information in the <code>query_posts</code> query, but doing so is a bit beyond the scope of this article.</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/12/limit-posts-without-plugin/">Permalink</a> | <a href="http://digwp.com/2009/12/limit-posts-without-plugin/#comments">18 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/12/limit-posts-without-plugin/&title=Two Ways to Limit the Number of Posts without a Plugin">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/loop/" rel="tag">loop</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</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/12/limit-posts-without-plugin/feed/</wfw:commentRss>
		<slash:comments>18</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>Look Ma, Editable Text Regions</title>
		<link>http://digwp.com/2009/09/look-ma-editable-text-regions/</link>
		<comments>http://digwp.com/2009/09/look-ma-editable-text-regions/#comments</comments>
		<pubDate>Thu, 03 Sep 2009 15:06:53 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[maintenance]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=622</guid>
		<description><![CDATA[WordPress is a CMS. The whole idea being to manage content and make websites editable without having to wrangle code. Any theme can handle Posts and Pages, but what about those &#8220;smaller&#8221; areas. Little chunks of text placed around a design like a small &#8220;about&#8221; section, or the copy in the footer of a website. [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress is a CMS. The whole idea being to manage content and make websites editable without having to wrangle code. Any theme can handle Posts and Pages, but what about those &#8220;smaller&#8221; areas. Little chunks of text placed around a design like a small &#8220;about&#8221; section, or the copy in the footer of a website. A lot of times this text is hard-baked right into the theme, which isn&#8217;t a very friendly way to do things, as it can&#8217;t be updated by average Joe user.</p>
<p><img src="http://digwp.com/wp-content/blog-images/editable-region.png" width="590" height="439" alt="" title="" /></p>
<p><span id="more-622"></span></p>
<h3>Widgetize!</h3>
<p>If you are looking to add text to your sidebar, and your sidebar is already widgetized, this becomes trivially easy. In your Admin, go to <strong>Appearance > Widgets</strong> and drag the &#8220;text&#8221; widget into the your sidebar area on the right. You can then open up that widget and give it a title and text and save it.</p>
<p><img src="http://digwp.com/wp-content/blog-images/widgetize.jpg" width="590" height="581" alt="" title="" /></p>
<h3>Adding Multiple Regions</h3>
<p>There is a good chance that if your theme is widgetized, the only widgetable area is the sidebar. But you are by no means limited to having only one widgetized area. In order to add another, open your <code>functions.php</code> file and add another chunk of code like this:</p>
<pre><code>if ( function_exists('register_sidebar') ) {
   register_sidebar(array(
       'name'=&gt;'Footer Widgets',
       'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s"&gt;',
       'after_widget' =&gt; '&lt;/div&gt;',
       'before_title' =&gt; '&lt;h4 class="widgettitle"&gt;',
       'after_title' =&gt; '&lt;/h4&gt;',
   ));
}</code></pre>
<p>The &#8216;name&#8217; part is important, because we&#8217;ll be referencing that in a sec when we drop in the widgetization code. Most of the rest of this should be pretty self-explanatory. You provide the HTML code for what wraps the text you provide for a title and body of the widget. Those weird characters as part of the ID and class actually provide some nice useful hooks for each widget. The ID is literally a unique ID for the widget, and the classes designate the type of widget being used. The end result markup for a simple text widget will be something like this:</p>
<pre><code>&lt;div class="widget widget_text" id="text-4"&gt;
   &lt;div class="textwidget"&gt;
       &lt;p&gt;Â©2009 Digging into WordPress&lt;/p&gt;
   &lt;/div&gt;
&lt;/div&gt;</code></pre>
<p>As you may have gathered, we are making an editable region in our footer to house the copyright information. In our <code>footer.php</code> file, we&#8217;ll drop in this code in an appropriate place to widgetize the area:</p>
<pre><code>&lt;?php if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar('Footer Widgets') ) : ?&gt;
&lt;?php endif; ?&gt;</code></pre>
<p>All goes well, we now have a new widget area showing up in our Admin, in which to drag in widgets. Drag in a text widget, and you should be all set. It should be noted that while text widgets have a title and text area, you don&#8217;t <strong>have</strong> to use both, you can use one or the other if you want.</p>
<p><img src="http://digwp.com/wp-content/blog-images/footerwidget.png" width="311" height="176" alt="" title="" /></p>
<p>Fairly basic stuff, but this is great stuff for allowing users to be in more complete command of their sites!</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/09/look-ma-editable-text-regions/">Permalink</a> | <a href="http://digwp.com/2009/09/look-ma-editable-text-regions/#comments">21 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/09/look-ma-editable-text-regions/&title=Look Ma, Editable Text Regions">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/html/" rel="tag">HTML</a>, <a href="http://digwp.com/tag/maintenance/" rel="tag">maintenance</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/09/look-ma-editable-text-regions/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Getting More Fine-Grained with Includes</title>
		<link>http://digwp.com/2009/07/getting-more-fine-grained-with-includes/</link>
		<comments>http://digwp.com/2009/07/getting-more-fine-grained-with-includes/#comments</comments>
		<pubDate>Tue, 28 Jul 2009 11:56:15 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=364</guid>
		<description><![CDATA[I was recently putting together a site where I found it very useful to have a number of small areas of the site as separate chunks of code I could include in templates at will. The site wasn&#8217;t unusual at all, it just never occurred to me to get this fine-grained with includes before, but [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently putting together a site where I found it very useful to have a number of small areas of the site as separate chunks of code I could include in templates at will. The site wasn&#8217;t unusual at all, it just never occurred to me to get this fine-grained with includes before, but I&#8217;m starting to do it now and I like it.</p>
<p>In my theme folder, I created a directory for &#8220;includes&#8221; which has a number of these little chunks of code:</p>
<p><img src="http://digwp.com/wp-content/blog-images/includemodules.jpg" width="292" height="415" alt="" title="" /></p>
<p><span id="more-364"></span></p>
<h3>blogtitlearea.php</h3>
<p>On this particular site, WordPress is used to power the entire site including a blog area that exists as a sub page (i.e. /blog/). Template files that specifically had to do with the blog area needed a special header area for the blog, whereas other page templates did not. This could have been solved with some elaborate if/then logic in the header.php file, but I found it more intuitive to create a special file with this &#8220;Blog Title Area&#8221; and include it on the template files that needed it.</p>
<p>For example, the index.php, archive.php and single.php files include the lovely blog title area:</p>
<pre><code>&lt;?php include( TEMPLATEPATH . '/includes/blogtitlearea.php' ); ?&gt;</code></pre>
<p>Whereas the search.php, 404.php, and page templates do not.</p>
<h3>metabar.php</h3>
<p>Underneath the Post tiles on this site was a red bar with information about the post. The data posted, the author, the categories, the number of comments. Otherwise known as &#8220;meta&#8221; information about the post.</p>
<p><img src="http://digwp.com/wp-content/blog-images/metabar.png" width="530" height="129" alt="" title="" /></p>
<p>This same exact &#8220;metabar&#8221; is present on a number of the different template files. For example, the blog home (index.php), the category views (archive.php), and the individual Post pages (single.php). The bit of code that was creating this bar was beginning to grow rather complex. For example, on one particular category I didn&#8217;t want to show it, and there are just a lot of PHP functions needed to gather all that data. </p>
<pre><code>&lt;?php if ((!is_category("5")) and (!in_category("5"))) { ?&gt;
        &lt;div class="metaBar"&gt;
		    &lt;p class="time"&gt;&lt;span&gt;Posted on&lt;/span&gt; &lt;?php the_time('F jS, Y') ?&gt; &lt;span&gt;by&lt;/span&gt; &lt;?php the_author(); ?&gt; &lt;span&gt;in&lt;/span&gt; &lt;?php the_category(' '); ?&gt;&lt;/p&gt;
		    &lt;p class="numComments"&gt;&lt;?php comments_popup_link('Add Comment &amp;#187;', '1 Comment &amp;#187;', '% Comments &amp;#187;'); ?&gt;&lt;/p&gt;
	&lt;/div&gt;
&lt;? } ?&gt;</code></pre>
<p>If I wanted to change anything, I would need to maintain it in many different places even though it is the same code. Instead of repeating myself, I just used an include:</p>
<pre><code>&lt;?php include( TEMPLATEPATH . '/includes/metabar.php' ); ?&gt;</code></pre>
<h3>prevnextlinks.php</h3>
<p>I bet you guys know what these are! Those links that show up on all kinds of different template pages to allow for going back and forward in time showing Posts.</p>
<pre><code>&lt;ul class="prev-next-links"&gt;
	&lt;li&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/li&gt;
	&lt;li&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/li&gt;
&lt;/ul&gt;</code></pre>
<p>These are commonly found on the blog home page, search pages, archive pages, and even sometimes individual post pages. If they are exactly the same on each, why not include them from one central file?</p>
<pre><code>&lt;?php include( TEMPLATEPATH . '/includes/prevnextlinks.php' ); ?&gt;</code></pre>
<h3>Other ideas?</h3>
<p>On the particular site I was working on, some of my page templates were specifically related to a &#8220;store&#8221; area of the site, so those needed to use my special &#8220;storenav.php&#8221; include. Do you guys ever use this technique? Are there other things you can think of to use this fine-grained include approach on?</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/getting-more-fine-grained-with-includes/">Permalink</a> | <a href="http://digwp.com/2009/07/getting-more-fine-grained-with-includes/#comments">25 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/getting-more-fine-grained-with-includes/&title=Getting More Fine-Grained with Includes">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/template/" rel="tag">template</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/getting-more-fine-grained-with-includes/feed/</wfw:commentRss>
		<slash:comments>25</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>Free HTML 5 WordPress Theme</title>
		<link>http://digwp.com/2009/07/free-html-5-wordpress-theme/</link>
		<comments>http://digwp.com/2009/07/free-html-5-wordpress-theme/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 07:19:43 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[CSS]]></category>
		<category><![CDATA[free]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[template]]></category>

		<guid isPermaLink="false">http://diggingintowordpress.com/?p=215</guid>
		<description><![CDATA[In an effort to inspire more WordPress theme designers to embrace HTML 5, I am releasing the &#8220;H5&#8221; Theme Template. The H5 Theme Template is a bare-bones WordPress theme built entirely with HTML 5 and styled with CSS 2.1. As you may know, HTML 5 provides greater flexibility and interoperability than previous markup languages, and [...]]]></description>
			<content:encoded><![CDATA[<p>In an effort to inspire more WordPress theme designers to embrace <acronym title="Hypertext Markup Language">HTML</acronym> 5, I am releasing the &ldquo;<acronym title="HTML 5">H5</acronym>&rdquo; Theme Template. The <acronym title="HTML 5">H5</acronym> Theme Template is a bare-bones WordPress theme built entirely with <acronym title="Hypertext Markup Language">HTML</acronym> 5 and styled with <acronym title="Cascading Style Sheets">CSS</acronym> 2.1. As you may know, <acronym title="Hypertext Markup Language">HTML</acronym> 5 provides greater flexibility and interoperability than previous markup languages, and enables us to build well-structured themes that are more flexible, interactive, and semantically precise.</p>
<p><span id="more-215"></span></p>
<h3>About the &lsquo;H5&rsquo; WordPress Theme Template</h3>
<p>The <acronym title="HTML 5">H5</acronym> Theme Template provides everything you need to create beautiful themes with <acronym title="Hypertext Markup Language">HTML</acronym> 5 <em>right now</em>. <acronym title="HTML 5">H5</acronym> contains a complete set of theme files and folders, and each file has been meticulously crafted with all of the latest and greatest WordPress functionality. As a template theme, <acronym title="HTML 5">H5</acronym> is designed with easy customization and personalization in mind, serving as a solid starting point for your next <acronym title="Hypertext Markup Language">HTML</acronym>-5-based theme.</p>
<p>Unlike other frameworks, <acronym title="HTML 5">H5</acronym> works great as a basic theme right out of the box. Of course, this is a <em>template</em> theme we&rsquo;re talking about here, so you will inevitably feel &ldquo;inspired&rdquo; to begin tweaking and styling its minimalistic appearance to get the design looking exactly how you want it. And that is entirely the point: <acronym title="HTML 5">H5</acronym> makes it quick and easy to begin designing themes with <acronym title="Hypertext Markup Language">HTML</acronym> 5. And best of all, <acronym title="HTML 5">H5</acronym> is completely <em>free</em>. Sound good? Great, let&rsquo;s dig into the specifics..</p>
<h3>&lsquo;H5&rsquo; Specifications</h3>
<p>First, thanks for your interest in the <acronym title="HTML 5">H5</acronym> Theme Template. I am very excited to be sharing this theme with the WordPress community and hope that you will put it to good use. Next, three important points that I would like to emphasize:</p>
<ul>
<li><acronym title="HTML 5">H5</acronym> is completely free and licensed under <a href="http://www.opensource.org/licenses/gpl-3.0.html" title="GNU General Public License version 3 (GPLv3)<br />
">GPL</a></li>
<li><acronym title="HTML 5">H5</acronym> is a <strong>template</strong> used to build <acronym title="Hypertext Markup Language">HTML</acronym>-5 themes</li>
<li><acronym title="HTML 5">H5</acronym> is built entirely with WordPress, <acronym title="Hypertext Markup Language">HTML</acronym> 5, and <acronym title="Cascading Style Sheets">CSS</acronym> 2.1</li>
</ul>
<p><strong>About the markup</strong></p>
<ul>
<li>Uses as few tags and attributes as possible</li>
<li>Contains no <code>&lt;div&gt;</code>s, <code>&lt;span&gt;</code>s, <code>class</code>es, or <code>id</code>s!</li>
<li>Built with semantically sound and fully valid <acronym title="Hypertext Markup Language">HTML</acronym> 5</li>
<li>Outputs clean, well-formatted source-code (although WordPress botches most of it)</li>
</ul>
<p><strong>About the CSS</strong></p>
<ul>
<li>Just enough <acronym title="Cascading Style Sheets">CSS</acronym> to target key elements, provide some structure, and make it &ldquo;look&rdquo; like a basic theme</li>
<li>Built with well-formatted and fully valid <acronym title="Cascading Style Sheets">CSS</acronym> 2.1 (current spec)</li>
<li>Uses child, adjacent, and attribute selectors to target elements without <code>id</code>s or <code>class</code>es</li>
</ul>
<p><strong>About the JavaScript</strong></p>
<ul>
<li>Uses only unobtrusive JavaScript</li>
<li>Uses <code>createElement()</code> to specify block elements for Internet Explorer</li>
<li>Includes WordPress&rsquo; jQuery script <a href="http://digwp.com/2009/06/including-jquery-in-wordpress-the-right-way/" title="Including jQuery in WordPress (The Right Way)">the right way</a></li>
</ul>
<p><strong>About the design</strong></p>
<ul>
<li>Includes minimal markup and styles for easy customization</li>
<li>Features a full set of theme template files and common folders</li>
<li>Very minimal, meant to do just the basics and serve as a starting point</li>
<li>Uses default and/or standard WordPress template tags, loops, and other functions</li>
<li>Looks and works great out of the box in (almost) all modern browsers (see next section)</li>
<li>Designed to be as lightweight and fast as possible &#8212; only essential tags are included</li>
</ul>
<p><strong>Browser compatibility</strong></p>
<p><acronym title="HTML 5">H5</acronym> looks and works great in the following browsers (and most likely others as well):</p>
<ul>
<li>Firefox 3</li>
<li>Opera 8*</li>
<li>Opera 9</li>
<li>Chrome 1 &amp; 2</li>
<li>Safari 2, 3, &amp; 4</li>
<li>Internet Explorer 7*</li>
<li>Internet Explorer 8</li>
</ul>
<p><small>* Denotes slight inconsistencies in these browsers.</small></p>
<p>For Firefox 2, Camino 1.6, and <acronym title="Internet Exploder">IE</acronym> 6, the <acronym title="Hypertext Markup Language">HTML</acronym> seems to work great, it&rsquo;s just some of the &ldquo;advanced&rdquo; <acronym title="Cascading Style Sheets">CSS</acronym> selectors that some browsers don&rsquo;t understand. <strong>This is easily handled by simply adding a few choice <code>id</code> or <code>class</code> attributes</strong> to key elements (none are used by default).</p>
<h3>Download and Demo</h3>
<p>For a &ldquo;live&rdquo; demo of the <acronym title="HTML 5">H5</acronym> Template Theme, check out our newly revamped <a href="http://themeplayground.digwp.com/index.php?wptheme=H5%20Theme%20Template" title="Launch the H5 Demo Theme">DiW Theme Playground</a>, where we will be hosting any themes that we release here at Digging into WordPress.</p>
<p>At the DiW Theme Playground you will find a dropdown menu at the top of the browser window that enables you to preview any of our themes, as well as a download link for whichever theme happens to be active (Chris&rsquo; excellent <a href="http://digwp.com/2009/06/free-theme-wp-typo/" title="Free Theme: WP Typo ">WP Typo</a> is the default active theme).</p>
<hr />
<p><small>© 2009 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2009/07/free-html-5-wordpress-theme/">Permalink</a> | <a href="http://digwp.com/2009/07/free-html-5-wordpress-theme/#comments">40 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2009/07/free-html-5-wordpress-theme/&title=Free HTML 5 WordPress Theme">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/css/" rel="tag">CSS</a>, <a href="http://digwp.com/tag/free/" rel="tag">free</a>, <a href="http://digwp.com/tag/html/" rel="tag">HTML</a>, <a href="http://digwp.com/tag/template/" rel="tag">template</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2009/07/free-html-5-wordpress-theme/feed/</wfw:commentRss>
		<slash:comments>40</slash:comments>
		</item>
	</channel>
</rss>

