<?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; 2010</title>
	<atom:link href="http://digwp.com/2010/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Take your WordPress skills to the next level.</description>
	<lastBuildDate>Fri, 17 May 2013 21:10:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Custom Login/Register/Password Code</title>
		<link>http://digwp.com/2010/12/login-register-password-code/</link>
		<comments>http://digwp.com/2010/12/login-register-password-code/#comments</comments>
		<pubDate>Thu, 16 Dec 2010 06:30:08 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Theme]]></category>
		<category><![CDATA[Admin]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3102</guid>
		<description><![CDATA[In this DiW post, we transform three slices of code into a clean &#38; stylish tabbed menu that visitors can use to login, register, and recover passwords from anywhere in your site. Too many features &#38; details to explain up front, so check out the working demo to see the finished product. On the menu: [...]]]></description>
				<content:encoded><![CDATA[<p>In this <abbr title="Digging into WordPress">DiW</abbr> post, we transform three slices of code into a clean &amp; stylish tabbed menu that visitors can use to login, register, and recover passwords from anywhere in your site. Too many features &amp; details to explain up front, so <a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">check out the working demo</a> to see the finished product. On the menu:</p>
<p><span id="more-3102"></span></p>
<ul>
<li><a href="#default">Default WordPress Login Page</a></li>
<li><a href="#moving">Moving the login/register/password form</a></li>
<li><a href="#code">Custom WordPress template code</a></li>
<li><a href="#demo">Implement and Demo</a></li>
<li><a href="#custom">Customizing things</a></li>
<li><a href="#wrap">Wrap up</a></li>
</ul>
<h3 id="default">Default WordPress Login Page</h3>
<p>Out of the box, WordPress uses <code>wp-login.php</code> for logging into the Admin, retrieving lost passwords, and registering for site membership. Each of these activities are handled on the same page, commonly referred to as the WordPress Login Page. </p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-01.jpg" alt="[ Screenshot: Default WordPress Login/Register Page ]" /><br /><small>Yep, it&rsquo;s the WordPress Login Page</small></p>
<p>As seen here, the Login Page shows the log-in form by default. Beneath the form are two links, &ldquo;Register&rdquo; and &ldquo;Lost your password?&rdquo;, which enable users to (yep, you guessed it) register and recover their password. </p>
<p>The cool thing about the Login Page is that the page doesn&rsquo;t reload when either of these links are clicked. Instead, the form instantly changes from login to register or password to whatever. All three forms are included on the <code>wp-login.php</code> page and hidden/revealed as-needed using JavaScript. This &ldquo;same-page&rdquo; functionality is key to setting up our own custom login/register/password form elsewhere in our theme.</p>
<h3 id="moving">Moving the login/register/password form</h3>
<p>While it&rsquo;s not a good idea to move the entire <code>wp-login.php</code> file, it is possible to display the login/register/password forms anywhere in your theme. For example, putting the forms in your <code>sidebar.php</code> make it super-easy for visitors to register and login from anywhere in your site (here is an <a href="http://angry-birds.net/" title="Angry Birds Galaxy">example</a>). You could even create a WordPress page for each event: login, registration, and password-recovery pages that are customized/optimized in some really unique, bad-ass way.</p>
<p>The key to mobilizing the login forms is ensuring that they&rsquo;ll work properly regardless of placement (before, after, or within the loop) in your theme template files. We also want to ensure that normal visitors who aren&rsquo;t logged in see the forms, but logged-in users do not (or see alternate content). </p>
<p>Basically, it should work exactly like the default WordPress login functionality, but with one exception: instead of redirecting to the Admin Area (for log-ins) or to the Login Page (for registrations/password-recovery), we want the user to <em>remain on the same page</em>. This enables your guests to log-in, register, and reset passwords without leaving whatever page they happen to be visiting. Here&rsquo;s the code to make it happen..</p>
<h3 id="code">Custom WordPress template code</h3>
<p>Here is the code to display the login/register/password form anywhere in your theme:</p>
<p><a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="Custom Login/Register/Password Code">view as plain text</a>
<pre><code>&lt;div id="login-register-password"&gt;

	&lt;?php global $user_ID, $user_identity; get_currentuserinfo(); if (!$user_ID) { ?&gt;

	&lt;ul class="tabs_login"&gt;
		&lt;li class="active_login"&gt;&lt;a href="#tab1_login"&gt;Login&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#tab2_login"&gt;Register&lt;/a&gt;&lt;/li&gt;
		&lt;li&gt;&lt;a href="#tab3_login"&gt;Forgot?&lt;/a&gt;&lt;/li&gt;
	&lt;/ul&gt;
	&lt;div class="tab_container_login"&gt;
		&lt;div id="tab1_login" class="tab_content_login"&gt;

			&lt;?php $register = $_GET['register']; $reset = $_GET['reset']; if ($register == true) { ?&gt;

			&lt;h3&gt;Success!&lt;/h3&gt;
			&lt;p&gt;Check your email for the password and then return to log in.&lt;/p&gt;

			&lt;?php } elseif ($reset == true) { ?&gt;

			&lt;h3&gt;Success!&lt;/h3&gt;
			&lt;p&gt;Check your email to reset your password.&lt;/p&gt;

			&lt;?php } else { ?&gt;

			&lt;h3&gt;Have an account?&lt;/h3&gt;
			&lt;p&gt;Log in or sign up! It&amp;rsquo;s fast &amp;amp; &lt;em&gt;free!&lt;/em&gt;&lt;/p&gt;

			&lt;?php } ?&gt;

			&lt;form method="post" action="&lt;?php bloginfo('url') ?&gt;/wp-login.php" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login"&gt;&lt;?php _e('Username'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="log" value="&lt;?php echo esc_attr(stripslashes($user_login)); ?&gt;" size="20" id="user_login" tabindex="11" /&gt;
				&lt;/div&gt;
				&lt;div class="password"&gt;
					&lt;label for="user_pass"&gt;&lt;?php _e('Password'); ?&gt;: &lt;/label&gt;
					&lt;input type="password" name="pwd" value="" size="20" id="user_pass" tabindex="12" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;div class="rememberme"&gt;
						&lt;label for="rememberme"&gt;
							&lt;input type="checkbox" name="rememberme" value="forever" checked="checked" id="rememberme" tabindex="13" /&gt; Remember me
						&lt;/label&gt;
					&lt;/div&gt;
					&lt;?php do_action('login_form'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Login'); ?&gt;" tabindex="14" class="user-submit" /&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
		&lt;div id="tab2_login" class="tab_content_login" style="display:none;"&gt;
			&lt;h3&gt;Register for this site!&lt;/h3&gt;
			&lt;p&gt;Sign up now for the good stuff.&lt;/p&gt;
			&lt;form method="post" action="&lt;?php echo site_url('wp-login.php?action=register', 'login_post') ?&gt;" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login"&gt;&lt;?php _e('Username'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_login" value="&lt;?php echo esc_attr(stripslashes($user_login)); ?&gt;" size="20" id="user_login" tabindex="101" /&gt;
				&lt;/div&gt;
				&lt;div class="password"&gt;
					&lt;label for="user_email"&gt;&lt;?php _e('Your Email'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_email" value="&lt;?php echo esc_attr(stripslashes($user_email)); ?&gt;" size="25" id="user_email" tabindex="102" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;?php do_action('register_form'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Sign up!'); ?&gt;" class="user-submit" tabindex="103" /&gt;
					&lt;?php $register = $_GET['register']; if($register == true) { echo '&lt;p&gt;Check your email for the password!&lt;/p&gt;'; } ?&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;?register=true" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
		&lt;div id="tab3_login" class="tab_content_login" style="display:none;"&gt;
			&lt;h3&gt;Lose something?&lt;/h3&gt;
			&lt;p&gt;Enter your username or email to reset your password.&lt;/p&gt;
			&lt;form method="post" action="&lt;?php echo site_url('wp-login.php?action=lostpassword', 'login_post') ?&gt;" class="wp-user-form"&gt;
				&lt;div class="username"&gt;
					&lt;label for="user_login" class="hide"&gt;&lt;?php _e('Username or Email'); ?&gt;: &lt;/label&gt;
					&lt;input type="text" name="user_login" value="" size="20" id="user_login" tabindex="1001" /&gt;
				&lt;/div&gt;
				&lt;div class="login_fields"&gt;
					&lt;?php do_action('login_form', 'resetpass'); ?&gt;
					&lt;input type="submit" name="user-submit" value="&lt;?php _e('Reset my password'); ?&gt;" class="user-submit" tabindex="1002" /&gt;
					&lt;?php $reset = $_GET['reset']; if($reset == true) { echo '&lt;p&gt;A message will be sent to your email address.&lt;/p&gt;'; } ?&gt;
					&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;?reset=true" /&gt;
					&lt;input type="hidden" name="user-cookie" value="1" /&gt;
				&lt;/div&gt;
			&lt;/form&gt;
		&lt;/div&gt;
	&lt;/div&gt;

	&lt;?php } else { // is logged in ?&gt;

	&lt;div class="sidebox"&gt;
		&lt;h3&gt;Welcome, &lt;?php echo $user_identity; ?&gt;&lt;/h3&gt;
		&lt;div class="usericon"&gt;
			&lt;?php global $userdata; get_currentuserinfo(); echo get_avatar($userdata-&gt;ID, 60); ?&gt;

		&lt;/div&gt;
		&lt;div class="userinfo"&gt;
			&lt;p&gt;You&amp;rsquo;re logged in as &lt;strong&gt;&lt;?php echo $user_identity; ?&gt;&lt;/strong&gt;&lt;/p&gt;
			&lt;p&gt;
				&lt;a href="&lt;?php echo wp_logout_url('index.php'); ?&gt;"&gt;Log out&lt;/a&gt; | 
				&lt;?php if (current_user_can('manage_options')) { 
					echo '&lt;a href="' . admin_url() . '"&gt;' . __('Admin') . '&lt;/a&gt;'; } else { 
					echo '&lt;a href="' . admin_url() . 'profile.php"&gt;' . __('Profile') . '&lt;/a&gt;'; } ?&gt;

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

	&lt;?php } ?&gt;

&lt;/div&gt;
</code></pre>
<p>Okay, so here are the functional highlights for this hefty chunk of code:</p>
<ul>
<li>Everything is wrapped with <code>&lt;div id="login-register-password"&gt;&lt;/div&gt;</code></li>
<li>If the user is <em>not</em> logged in, the three forms are <em>included</em> in the markup</li>
<li>If the user <em>is</em> logged in, a simple welcome message is displayed</li>
<li>Success messages are displayed after both password recovery and registration</li>
<li>Each form submission sets a generic <code>user-cookie</code></li>
<li>After login or registration, the script redirects the user to the same page</li>
<li>Only one form is shown at a time; JavaScript is used to show and hide forms</li>
</ul>
<p>So if you just throw this thing into your <code>sidebar.php</code> file, you&rsquo;ll see the login form and three links: login, register, and recover-password. The other two forms are included in the markup, but are hidden with <abbr title="Cascading Style Sheets">CSS</abbr> (<code>display:none;</code>). As-is, the three links won&rsquo;t do anything because they require JavaScript to work. Once we sprinkle in some jQuery, the links will toggle the three different forms.</p>
<h3 id="demo">Implement and Demo</h3>
<p>First let&rsquo;s walk through using this code in your theme, and then we&rsquo;ll check out a demo.</p>
<ol>
<li>Place the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="Custom Login/Register/Password Code">custom login code</a> in your <code>sidebar.php</code> file, or some other location</li>
<li>Grab the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-01.txt" title="jQuery Code">jQuery code</a> (no-conflict mode) and include it in your <code>footer.php</code> file</li>
<li>Include the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">CSS code</a> in your theme&rsquo;s <code>style.css</code> file, or wherever your styles are located</li>
</ol>
<p>..and done. Once these three items are in place, upload everything to your server and check it out. Here is a <strong><a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">demo</a></strong> showing this code used on a custom page <em>within</em> the loop. </p>
<p>Note that we have registration disabled here at <a href="http://digwp.com/" title="Digging into WordPress">DigWP.com</a>, so the forms won&rsquo;t be of much use other than to show how the tabs work and how the forms are styled. Here are some screenshots showing the &ldquo;success&rdquo; messages, and also the &ldquo;logged-in&rdquo; display.</p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-02.gif" alt="[ Screenshot: Registration Success Message ]" /><br /><small>Message displayed on successful registration</small></p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-03.gif" alt="[ Screenshot: Password-Recovery Success Message ]" /><br /><small>Message displayed on successful password-recovery</small></p>
<p><img src="http://digwp.com/wp-content/blog-images/custom-login-04.gif" alt="[ Screenshot: Logged-In View ]" /><br /><small>Content displayed when user is logged into the site</small></p>
<p>Here again is the <a href="http://digwp.com/custom-login-demo/" title="Custom Login Demo">demo</a> and here are the three resource files:</p>
<ul>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-01.txt" title="Custom Login/Register/Password Code">Custom Template Code</a></li>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-02.txt" title="jQuery Code">jQuery Code</a></li>
<li><a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">CSS Code</a></li>
</ul>
<h3 id="custom">Customizing things</h3>
<p>One of the main reasons why we like working with actual code instead of widgets or plugins is the ability to easily customize anything we want exactly how we want it. With this implementation, there are basically three things to customize: the jQuery, the custom login code, and the <abbr title="Cascading Style Sheets">CSS</abbr>. As with any code, there are countless ways to modify appearance and functionality, so hopefully you have something specific in mind, and are familiar enough with design to jump in and customize things. If not, no worries &ndash; here are some ideas to help get you started.</p>
<h4>Customizing the login forms</h4>
<p>As-is, the custom login forms redirect to the current page. To get any/all of the forms to redirect to a different page, locate and edit the following line of code:</p>
<pre><code>&lt;input type="hidden" name="redirect_to" value="&lt;?php echo $_SERVER['REQUEST_URI']; ?&gt;" /&gt;</code></pre>
<p>There are three instances of this hidden input field, which WordPress uses to perform the redirect. The <code>value</code> returns the current <abbr title="Uniform Resource Locator">URL</abbr>, so that&rsquo;s what needs changed for each form to redirect elsewhere.</p>
<p>Another useful modification involves customizing what the logged-in users see. Showing the gravatar and username is kind of neat, but there are tons of cool tricks to help ensure smooth user experience.</p>
<h4>Customizing the jQuery</h4>
<p>The jQuery used to show/hide the different login panels is actually pretty basic and is only used for toggling display states. I suppose there is a way to customize this, but it already handles additional menu items, so maybe you want to change the class names or optimize the script or something.</p>
<p>I do love to look at a nice slice of well-formatted jQuery, however, so I&rsquo;ll further indulge myself by including the entire code snippet right here:</p>
<pre><code>&lt;script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript"&gt;
	$(document).ready(function() {
		$(".tab_content_login").hide();
		$("ul.tabs_login li:first").addClass("active_login").show();
		$(".tab_content_login:first").show();
		$("ul.tabs_login li").click(function() {
			$("ul.tabs_login li").removeClass("active_login");
			$(this).addClass("active_login");
			$(".tab_content_login").hide();
			var activeTab = $(this).find("a").attr("href");
			if ($.browser.msie) {$(activeTab).show();}
			else {$(activeTab).show();}
			return false;
		});
	});
&lt;/script&gt;</code></pre>
<p>A bit heavy-handed perhaps, but works great with no editing required ;)</p>
<h4>Customizing the CSS</h4>
<p>To get that fancy tabbed form menu looking all clean and rounded, <em>much</em> <abbr title="Cascading Style Sheets">CSS</abbr> is used. So instead of posting endless gobs of <abbr title="Cascading Style Sheets">CSS</abbr>, here is the <a href="http://digwp.com/examples/CustomLoginCode/custom-login-03.txt" title="CSS Code">code in plain text</a>. As with any <abbr title="Cascading Style Sheets">CSS</abbr>, the best way to customize things is to open Firebug and start tweaking.</p>
<h4>Just the links</h4>
<p>One last trick: use this code to display <em>links</em> to the default WordPress login/registration page:</p>
<pre><code>&lt;ul&gt;
	&lt;?php wp_register(); ?&gt;
	&lt;li&gt;&lt;?php wp_loginout(); ?&gt;&lt;/li&gt;
	&lt;?php wp_meta(); ?&gt;
&lt;/ul&gt;</code></pre>
<p>Nothing to golf about, but I figured it was worth mentioning.</p>
<h3 id="wrap">Wrap up</h3>
<p>Using the code and techniques in this article, you can provide your readers with a login form anywhere on your site. This makes it easy for your users and visitors to login/logout, register for your site, and recover passwords without leaving their current page. The login code works great as-is or is easily transformed into a snazzily tabbed login menu using a sprinkle of <abbr title="Cascading Style Sheets">CSS</abbr> and a dash of jQuery.</p>
<p>Finally, one of the great things about WordPress is that there is always more than one way to set things up. So if you see a way to improve the code, please share with the community by leaving a comment. Thank you!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/12/login-register-password-code/">Permalink</a> | <a href="http://digwp.com/2010/12/login-register-password-code/#comments">63 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/12/login-register-password-code/&title=Custom Login/Register/Password Code">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/admin/" rel="tag">Admin</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/12/login-register-password-code/feed/</wfw:commentRss>
		<slash:comments>63</slash:comments>
		</item>
		<item>
		<title>Custom Message After the Comments</title>
		<link>http://digwp.com/2010/12/custom-message-after-comments/</link>
		<comments>http://digwp.com/2010/12/custom-message-after-comments/#comments</comments>
		<pubDate>Mon, 06 Dec 2010 18:14:27 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[functions.php]]></category>
		<category><![CDATA[message]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3377</guid>
		<description><![CDATA[Have you ever wanted to close a comment thread, but leave a note to communicate why the thread is closed? Many blogs will just update the content of the blog post to say that comments are closed and why. That&#8217;s better than nothing, but that puts the message in a bit of an awkward place. [...]]]></description>
				<content:encoded><![CDATA[<p>Have you ever wanted to close a comment thread, but leave a note to communicate why the thread is closed? Many blogs will just update the content of the blog post to say that comments are closed and why. That&#8217;s better than nothing, but that puts the message in a bit of an awkward place. The ideal place for that custom messaging is <em>after</em> the comment thread, where the comment form would <em>normally</em> be.</p>
<p><span id="more-3377"></span></p>
<p>One example situation is the contest we just ran. Like many blog-based comments, it was comment-to-win. That means it&#8217;s best to close the comments when the contest is over, so people clearly understand that it&#8217;s over. We do close comments after a few months on this site to avoid spam and questions that come in way after the fact and will probably never be answered, but this is a case where we close comments much sooner than a few months. When we closed the contest, we actually put the winners of it as a custom message beneath the comment thread. </p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/uploads/custommessage.png" alt="" title="custommessage" width="590" height="260" class="alignnone size-full wp-image-3469" />
</div>
<p>To accomplish this in a very easy-to-use manner, we&#8217;ll create a custom meta box inside the Post Editor itself.</p>
<p><!--more--></p>
<h3>Functions.php</h3>
<p>We need to hook into two actions for this. We&#8217;ll use the &#8216;admin_menu&#8217; and &#8216;add_meta_box&#8217; to create the meta box. Then we&#8217;ll tap into &#8216;save_post&#8217; and use &#8216;update_post_meta&#8217; to actually save the value entered.</p>
<pre><code>// After Comments Message

add_action('admin_menu', 'custom_comments_message_hooks');
add_action('save_post', 'save_custom_comments_message');

function custom_comments_message_hooks() {
	add_meta_box('custom_comments_message', 'Custom Comments Message', 'custom_comments_message_input', 'post', 'normal', 'high');
}
function custom_comments_message_input() {
	global $post;
	echo '
&lt;input id="custom_comments_message_noncename" name="custom_comments_message_noncename" type="hidden" value="'.wp_create_nonce('custom_comments_message').'" /&gt;';
	echo '&lt;textarea id="custom_comments_message" style="width: 100%;" cols="30" rows="5" name="custom_comments_message"&gt;'.get_post_meta($post-&amp;gt;ID,'_custom_comments_message',true).'&lt;/textarea&gt;';
}
function save_custom_comments_message($post_id) {
	if (!wp_verify_nonce($_POST['custom_comments_message_noncename'], 'custom_comments_message')) return $post_id;
	if (defined('DOING_AUTOSAVE') &amp;amp;&amp;amp; DOING_AUTOSAVE) return $post_id;
	$custom_comments_message = $_POST['custom_comments_message'];
	update_post_meta($post_id, '_custom_comments_message', $custom_comments_message);
}</code></pre>
<p>That is the entire UI for creating this functional data-saving meta box. Now we just need to actually use that value.</p>
<h3>Comments.php</h3>
<p>There is some logic in the comments.php file which tests if comments are open or not. If they are, the comment form is output, if they are not, some kind of &#8220;comments closed&#8221; message is output. We&#8217;ll be tinkering around in the &#8220;if they are not&#8221; section (the &#8220;else&#8221; code below) and adding a check for our special custom field value. If it&#8217;s present, output that, if not, output the default.</p>
<pre><code>&lt;?php if ( comments_open() ) :

  // regular outputting of comments stuff in here

&lt;?php else: 

	global $post;

	$custom_message = get_post_meta($post-&gt;ID, '_custom_comments_message', true);
		
	if ($custom_message != '') {
		
		echo '&lt;div id="after-comments-message"&gt;';
		echo $custom_message;
		echo "&lt;/div&gt;";
		
	} else {
	
		echo '&lt;div id="after-comments-message"&gt;Comments are closed. If you have something really important to add, &lt;a href="/contact/"&gt;contact us&lt;/a&gt;. Thank you!&lt;/div&gt;';
	
	} ?&gt;
	
&lt;?php endif; ?&gt;</code></pre>
<p>That&#8217;s all there is to it! Now you have a fancy custom box right in your Post Editor where, should you choose, you can close comments and write a custom message to display after the existing comments. </p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/12/custom-message-after-comments/">Permalink</a> | <a href="http://digwp.com/2010/12/custom-message-after-comments/#comments">15 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/12/custom-message-after-comments/&title=Custom Message After the Comments">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/comments/" rel="tag">comments</a>, <a href="http://digwp.com/tag/functions-php/" rel="tag">functions.php</a>, <a href="http://digwp.com/tag/message/" rel="tag">message</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/12/custom-message-after-comments/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>WP Candy iPhone App</title>
		<link>http://wpcandy.com/announces/the-wpcandy-iphone-app</link>
		<comments>http://digwp.com/2010/12/wp-candy-iphone-app/#comments</comments>
		<pubDate>Wed, 01 Dec 2010 14:48:48 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3466</guid>
		<description><![CDATA[I think WP Candy is really killing it lately being a great source of breaking quality WordPress news, interviews, and other articles. Now they have an iPhone app they developed in-house to bring all the content to you that way. They are rolling it out &#8220;reverse&#8221; style, where for two weeks it&#8217;s $5.99 then later [...]]]></description>
				<content:encoded><![CDATA[<p>I think WP Candy is really killing it lately being a great source of breaking quality WordPress news, interviews, and other articles. Now they have an iPhone app they developed in-house to bring all the content to you that way. They are rolling it out &#8220;reverse&#8221; style, where for two weeks it&#8217;s $5.99 then later it drops to $0.99, so it&#8217;s an opportunity for the community to opt-in to paying more to support the site, which is neat, especially considering their crazy no advertising policy.</p>
<p><small><a href="http://wpcandy.com/announces/the-wpcandy-iphone-app" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://digwp.com/2010/12/wp-candy-iphone-app/" title="Permalink to post on DiW">Permalink on DiW</a></small></p><hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/12/wp-candy-iphone-app/">Permalink</a> | <a href="http://digwp.com/2010/12/wp-candy-iphone-app/#comments">No comment</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/12/wp-candy-iphone-app/&title=WP Candy iPhone App">del.icio.us</a> | Post tags: <br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/12/wp-candy-iphone-app/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MediaElements.js WordPress Plugin</title>
		<link>http://wordpress.org/extend/plugins/media-element-html5-video-and-audio-player/</link>
		<comments>http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 23:43:39 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3464</guid>
		<description><![CDATA[MediaElements.js is an open source jQuery-based project (which I use and like) which allows you to use HTML5 video and audio in any browser all the way back to IE 6. It tests if the browser supports HTML5. If yes, it uses that. If no, it falls back to displaying the media through Silverlight or [...]]]></description>
				<content:encoded><![CDATA[<p>MediaElements.js is an open source jQuery-based project (which I use and like) which allows you to use HTML5 video and audio in any browser all the way back to IE 6. It tests if the browser supports HTML5. If yes, it uses that. If no, it falls back to displaying the media through Silverlight or Flash. Regardless of what it uses, the UI is always consistant.</p>
<p>Now available as a WordPress plugin to make it even easier. Just use simple shortcodes to link up the video and specify what options you want (e.g. autoplay, fullscreen, etc).</p>
<p><small><a href="http://wordpress.org/extend/plugins/media-element-html5-video-and-audio-player/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/" title="Permalink to post on DiW">Permalink on DiW</a></small></p><hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/">Permalink</a> | <a href="http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/#comments">No comment</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/&title=MediaElements.js WordPress Plugin">del.icio.us</a> | Post tags: <br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/11/mediaelements-js-wordpress-plugin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Make the Visual Editor Actually WYSIWYG</title>
		<link>http://digwp.com/2010/11/actual-wysiwyg/</link>
		<comments>http://digwp.com/2010/11/actual-wysiwyg/#comments</comments>
		<pubDate>Sun, 28 Nov 2010 16:18:14 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[editor]]></category>
		<category><![CDATA[functions.php]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3212</guid>
		<description><![CDATA[In otherwords, match what you see when creating/editing a Post or Page in the WordPress visual editor to what you get when you actually publish it. It&#8217;s easier than you might think! Basically you can declare a special CSS file that the visual editor will use to render itself while you are editing it. If [...]]]></description>
				<content:encoded><![CDATA[<p>In otherwords, match what you see when creating/editing a Post or Page in the WordPress visual editor to what you get when you actually publish it. It&#8217;s easier than you might think! Basically you can declare a special CSS file that the visual editor will use to render itself while you are editing it. If the styles in that CSS file match the styles in your live theme&#8217;s CSS file, you are straight up WYSIWYG (What You See Is What You Get).</p>
<p><span id="more-3212"></span></p>
<h3>1) Declare CSS for Visual Editor</h3>
<p>Very easy, one-liner in your functions.php file.</p>
<pre><code>// Add CSS to Visual Editor
add_editor_style('css/custom-editor-style.css');</code></pre>
<p>The file path that you pass as a parameter is relative to your theme&#8217;s root. Make sure to actually create this file in your theme folder, at the specified location!</p>
<h3>2) Make Sure You Have a Common Class To Work With</h3>
<p>The HTML markup for the posts on your site are very likely wrapped within a container element. Perhaps something like:</p>
<pre><code>&lt;div class="post"&gt;
  &lt;!-- all content for entire post in here --&gt;
&lt;/div&gt;</code></pre>
<p>Then your typography CSS likely uses that class name to to create typography specific to posts:</p>
<pre><code>.post h1, .post h2, .post h3, .post h4 { font-family: MuseoLight, Georgia, serif; font-weight: normal; margin: 0 0 10px 0; }
.post h2 { font-size: 28px; }
.post h2 { padding: 10px 180px 10px 15px; background: #237abf url(../images/title-bg.png) repeat-x; margin: 0; line-height: 1.3; font-size: 22px; }
.post h2, .post h2 a { color: white; text-shadow: 0 1px 2px #143855; }
.post h2 a:hover { color: #b8e0ff; }
.post h3 { font-size: 20px; padding: 5px 0; margin: 30px 0 15px 0; border-top: 1px solid #ccc; border-bottom: 1px solid #ccc; }
.post h4 { font-size: 18px; }
.post p { margin: 0 0 10px 0; }
.post pre { background: #eee; padding: 15px; overflow: auto; margin: 0 0 15px 0; border: 1px solid #ddd; }
.post pre code { font-size: 11px; }
.post code { background: #eee; font: 12px Monaco, Courier, Monospace; color: #0E304A; }
.post h3 code { font-size: 18px; }
.post acronym, abbr { border-bottom: 1px dotted #514031; cursor: help; }
.post ins { text-decoration: underline; }
.post del { text-decoration: line-through; }
.post a { outline: none; text-decoration: none; color: #19517C; background: #eee; border: 1px solid #ddd; padding: 1px 3px 2px 3px; -webkit-border-radius: 3px; -khtml-border-radius: 3px; -moz-border-radius: 3px; border-radius: 3px; }
.post a:hover { color: #fff; background: #143855; border: 1px solid #143855; }</code></pre>
<p>It would be nice if we could just copy and paste that over to the CSS file we declared in Step 1. The problem is, the Visual Editor doesn&#8217;t have that same class name inside of it. So if we did a straight up copy-and-paste, none of these styles would apply. Rather than re-jigger all our CSS to not use that class name, we can actually just force the visual editor to also have that class name.</p>
<p>Just put this in functions.php:</p>
<pre><code>// Add body class to Visual Editor to match class used live
function mytheme_mce_settings( $initArray ){
 $initArray['body_class'] = 'post';
 return $initArray;
}
add_filter( 'tiny_mce_before_init', 'mytheme_mce_settings' );</code></pre>
<p>This isn&#8217;t quite as efficient as referencing a single file, but at least you can copy and paste easily. If you are the type of person who separates CSS out into different files (like Typography has it&#8217;s own typography.css), then you are more than welcome to reference the same CSS both for Visual Editor and in the live theme. That&#8217;s just now how I roll.</p>
<p>The body class trick is from <a href="http://moronicbajebus.com/">Seamus Leahy</a>. Thanks Seamus!</p>
<h3>The Result:</h3>
<p>Check out this example of this very post from back end to front end:</p>
<p><img src="http://digwp.com/wp-content/uploads/sametypography.jpg" alt="" title="sametypography" width="591" height="470" class="alignnone size-full wp-image-3408" /></p>
<p>You can literally do anything CSS can do, right down to the custom web fonts!</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/11/actual-wysiwyg/">Permalink</a> | <a href="http://digwp.com/2010/11/actual-wysiwyg/#comments">26 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/11/actual-wysiwyg/&title=Make the Visual Editor Actually WYSIWYG">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/editor/" rel="tag">editor</a>, <a href="http://digwp.com/tag/functions-php/" rel="tag">functions.php</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/11/actual-wysiwyg/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>DiW Contest Winners!</title>
		<link>http://digwp.com/2010/11/book-giveaway-holiday-sale/#contest-winners</link>
		<comments>http://digwp.com/2010/11/diw-contest-winners/#comments</comments>
		<pubDate>Sat, 27 Nov 2010 00:01:30 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3394</guid>
		<description><![CDATA[Congratulations to all 10 of our Holiday Giveaway Contest Winners! Thank you to everyone who entered (click through to see who won)! Direct Link to Article &#8212; Permalink on DiW © 2010 Digging into WordPress &#124; Permalink &#124; No comment &#124; Add to del.icio.us &#124; Post tags:]]></description>
				<content:encoded><![CDATA[<p><strong>Congratulations</strong> to all 10 of our <a href="http://digwp.com/2010/11/book-giveaway-holiday-sale/" title="DiW Book Giveaway and Holiday Sale!">Holiday Giveaway</a> Contest Winners! <strong>Thank you</strong> to everyone who entered (click through to see who won)!</p>
<p><small><a href="http://digwp.com/2010/11/book-giveaway-holiday-sale/#contest-winners" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://digwp.com/2010/11/diw-contest-winners/" title="Permalink to post on DiW">Permalink on DiW</a></small></p><hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/11/diw-contest-winners/">Permalink</a> | <a href="http://digwp.com/2010/11/diw-contest-winners/#comments">No comment</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/11/diw-contest-winners/&title=DiW Contest Winners!">del.icio.us</a> | Post tags: <br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/11/diw-contest-winners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DiW Book Giveaway and Holiday Sale!</title>
		<link>http://digwp.com/2010/11/book-giveaway-holiday-sale/</link>
		<comments>http://digwp.com/2010/11/book-giveaway-holiday-sale/#comments</comments>
		<pubDate>Mon, 22 Nov 2010 12:29:44 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Site News]]></category>
		<category><![CDATA[book]]></category>
		<category><![CDATA[sale]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3221</guid>
		<description><![CDATA[Three big things for all the folks out there who are thinking about buying our book Digging Into WordPress for themselves or as a gift for someone this year. 

1. A Giveaway!
2. Special Holiday Discounts
3. A Scratch &#038; Dent Sale]]></description>
				<content:encoded><![CDATA[<p>To celebrate this magical time of year, we&rsquo;re giving away FREE copies of <a href="http://digwp.com/book/" title="Learn more and get the book!">Digging into WordPress</a> and throwing a HUGE Holiday Sale! PLUS we&rsquo;re selling a limited number of slightly damaged books for $15 OFF. <span id="more-3221"></span> Here&rsquo;s the scoop on all three of these fun-filled holiday events:</p>
<ul>
<li><a href="#giveaway"><abbr title="Digging into WordPress">DiW</abbr> Book Giveaway</a></li>
<li><a href="#holiday"><abbr title="Digging into WordPress">DiW</abbr> Holiday Sale</a></li>
<li><a href="#snd"><abbr title="Digging into WordPress">DiW</abbr> Scratch-n-Dent Sale</a></li>
</ul>
<h3 id="giveaway" class="holiday-sale">Book Giveaway!</h3>
<p>To kick off the holiday event, we&rsquo;re giving away <strong>10 awesome prizes</strong>:</p>
<ul id="holiday-list">
<li><strong class="holiday-num">1</strong> <a href="http://digwp.com/2010/09/v3-printed-books/" title="Learn more about DiW print edition">printed edition</a> of Digging into WordPress <small>(includes everything + free shipping)</small></li>
<li><strong class="holiday-num">3</strong> <a href="http://digwp.com/2010/09/version-3/" title="Learn more about DiW e-books">digital copies</a> of Digging into WordPress <small>(PDF, includes themes + lifetime updates)</small></li>
<li><strong class="holiday-num">3</strong> discount coupons for <strong>$20 OFF</strong> <abbr title="Digging into WordPress">DiW</abbr> Printed Books</li>
<li><strong class="holiday-num">3</strong> discount coupons for <strong>$10 OFF</strong> <abbr title="Digging into WordPress">DiW</abbr> PDF Books</li>
</ul>
<p>To enter the contest, just <a href="#comments" title="Enter to Win!">leave a comment</a> about how you utilize WordPress and/or why you read this blog. We&rsquo;ll randomly choose the <strong>10 winners</strong> on Black Friday <small>(November 26, 2010)</small>. </p>
<p>If you win a discount coupon but already own or don&#8217;t want to/can&#8217;t purchase the book, feel free to give it away to a friend. </p>
<h3 id="holiday" class="holiday-sale">Holiday Book Sale!</h3>
<p>In addition to the Book Giveaway, we&rsquo;re throwing a <strong><abbr title="Digging into WordPress">DiW</abbr> Holiday Sale!</strong> From now until December 10th, you can get Digging into WordPress for <strong>$5 off the <abbr title="Portable Document Format">PDF</abbr></strong> and <strong>$10 off the printed edition</strong>. Just use these discount codes during checkout:</p>
<ul>
<li>$5 off the e-book (PDF): <code>LetItSnow</code></li>
<li>$10 off the printed edition + e-book: <code>HoHoHo</code></li>
</ul>
<p>All books include <em>free lifetime updates</em>, exclusive WordPress themes, and access to our <a href="http://digwp.com/2010/11/new-updates-downloads-system/" title="New Updates/Downloads System">DigWP.com members area</a>, where you can download anything you need anytime you want. Sound good? <a href="http://digwp.com/book/">Go here to get Digging into WordPress</a> at these limited-time sale prices.</p>
<h3 id="snd" class="holiday-sale">Scratch &amp; Dent Sale</h3>
<p>We&rsquo;re also offering a <strong>$15 discount</strong> for a <em>limited number</em> of printed books that were scratched &amp; dented during the printing/shipping process. These &ldquo;scratch &amp; dent&rdquo; books are all packaged up and ready to ship to anyone who doesn&rsquo;t mind a few dingers. Most of these books are actually in pretty decent condition &ndash; check out these photos (click for full-size view):</p>
<div style="width:100%;overflow:auto;clear:both;margin:10px 0 15px 0;"><a href="http://digwp.com/wp-content/blog-images/snd-scratch-full.jpg" title="Click for full-size view" style="float:left;clear:none;margin-right:15px;"><img src="http://digwp.com/wp-content/blog-images/snd-scratch-thmb.jpg" alt="[ Close-up of scratched cover ]" style="float:left;" /></a><a href="http://digwp.com/wp-content/blog-images/snd-dent-full.jpg" title="Click for full-size view" style="float:left;clear:none;"><img src="http://digwp.com/wp-content/blog-images/snd-dent-thmb.jpg" alt="[ Close-up of dented cover ]" style="float:left;" /></a></div>
<p>Most of these books have some light scuffs or scratches on the front/back covers, but the pages are all perfectly fine. <em>A few of them</em> have some bent corners and other dings, but those are at the bottom of the stack (<em>hint hint</em>). Please note that the scratch-n-dent books are sold strictly on an &ldquo;<strong>as-is</strong>&rdquo; basis. <a href="http://digwp.com/book/scratch-dent-book-sale/" title="Scratch &amp; Dent Sale!">Go here to grab one of these books for $55</a> while supplies last.</p>
<h3>Happy Holidays!</h3>
<p>We want to thank everyone for making Digging into WordPress such an awesome experience. We wish you and yours a very special Holiday Season! :)</p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/11/book-giveaway-holiday-sale/">Permalink</a> | <a href="http://digwp.com/2010/11/book-giveaway-holiday-sale/#comments">156 comments</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/11/book-giveaway-holiday-sale/&title=DiW Book Giveaway and Holiday Sale!">del.icio.us</a> | Post tags: <a href="http://digwp.com/tag/book/" rel="tag">book</a>, <a href="http://digwp.com/tag/sale/" rel="tag">sale</a><br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/11/book-giveaway-holiday-sale/feed/</wfw:commentRss>
		<slash:comments>156</slash:comments>
		</item>
		<item>
		<title>How to Ajaxify Your WordPress Site</title>
		<link>http://www.problogger.net/archives/2010/11/19/how-to-ajaxify-your-wordpress-site/</link>
		<comments>http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/#comments</comments>
		<pubDate>Fri, 19 Nov 2010 17:04:11 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Links]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=3215</guid>
		<description><![CDATA[Without touching a line of code, you can harness the power of Ajax to boost performance, improve usability, and fill your site with win. Direct Link to Article &#8212; Permalink on DiW © 2010 Digging into WordPress &#124; Permalink &#124; No comment &#124; Add to del.icio.us &#124; Post tags:]]></description>
				<content:encoded><![CDATA[<p>Without touching a line of code, you can harness the power of Ajax to boost performance, improve usability, and fill your site with win.</p>
<p><small><a href="http://www.problogger.net/archives/2010/11/19/how-to-ajaxify-your-wordpress-site/" title="Direct link to featured article">Direct Link to Article</a> &#8212; <a href="http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/" title="Permalink to post on DiW">Permalink on DiW</a></small></p><hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/">Permalink</a> | <a href="http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/#comments">No comment</a> | Add to <a href="http://del.icio.us/post?url=http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/&title=How to Ajaxify Your WordPress Site">del.icio.us</a> | Post tags: <br/></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/11/how-to-ajaxify-your-wordpress-site/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
