<?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; PHP</title>
	<atom:link href="http://digwp.com/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://digwp.com</link>
	<description>Learn how to take your WordPress skills to the next level.</description>
	<lastBuildDate>Wed, 01 Sep 2010 14:47:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Pimp your&#160;wp-config.php</title>
		<link>http://digwp.com/2010/08/pimp-your-wp-config-php/</link>
		<comments>http://digwp.com/2010/08/pimp-your-wp-config-php/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 18:52:39 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[performance]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2416</guid>
		<description><![CDATA[Easily, the most important file in your WordPress installation is the wp-config.php file. It serves as your site&#8217;s base configuration file, controlling key aspects of WordPress&#8217; functionality and enabling WordPress to do mission-critical stuff like connect to the database. Without wp-config.php, WordPress simply won&#8217;t work. So whenever you install WordPress, one of the first things [...]]]></description>
			<content:encoded><![CDATA[<p>Easily, the most <em>important</em> file in your WordPress installation is the <code>wp-config.php</code> file. It serves as your site&rsquo;s <strong>base configuration file</strong>, controlling <em>key aspects</em> of WordPress&rsquo; functionality and enabling WordPress to do mission-critical stuff like connect to the database. Without <code>wp-config.php</code>, WordPress simply won&rsquo;t work. So whenever you install WordPress, one of the <em>first</em> things to do is pimp your <code>wp-config.php</code>.</p>
<p>And it&rsquo;s pretty easy too &ndash; just get your database credentials in place and you&rsquo;re done. The other settings available in the <code>wp-config.php</code> file will work just fine using the default values, but there are some <em>cool things</em> you can do to customize functionality, tighten security, and improve performance. Once you get the basics of <code>wp-config.php</code>, you can really <em>pimp it out</em> to do some awesome stuff. We&rsquo;ll break this down into <strong>four basic parts</strong>:</p>
<ul>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#basics" title="There is no wp-config.php..">Basics</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#security" title="Protect wp-config.php">Security</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#settings" title="Main Configuration Settings">Main Settings</a></li>
<li><a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#pimpin" title="Pimp it out!">Additional Tips and Tricks</a></li>
</ul>
<p><span id="more-2416"></span></p>
<h3 id="basics">There is no wp-config.php..</h3>
<p>When you first download WordPress, the <code>wp-config.php</code> file isn&rsquo;t included. Instead, you get a file named &ldquo;<code>wp-config-sample.php</code>&rdquo; (located in the root install-directory) that contains everything you need. Just rename the file to &ldquo;<code>wp-config.php</code>&rdquo; and delete the <code>wp-config-sample.php</code> file from the server if it&rsquo;s already there. Here is a visual:</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-config-01.jpg" alt="[ Rename the file ]" /></p>
<p>With the <code>wp-config.php</code> file now ready to go, it&rsquo;s time to protect it..</p>
<h3 id="security">Protect wp-config.php</h3>
<p>The first thing you want to do with <code>wp-config.php</code> is protect it. Here is a great way to secure the file using .htaccess:</p>
<pre><code>&lt;Files wp-config.php&gt;
	Order Allow,Deny
	Deny from all
&lt;/Files&gt;</code></pre>
<p>This code should be placed in an .htaccess file located in the directory that contains your <code>wp-config.php</code> file.</p>
<p><img src="http://digwp.com/wp-content/blog-images/wp-config-02.jpg" alt="[ Use the same directory ]" /></p>
<p>Once the .htaccess file is in place, ensure that permissions are <abbr title="change mode">chmod</abbr> <strong>640</strong> for both files. This setting returns a &ldquo;403 Forbidden&rdquo; error to all external requests. Combining proper file permissions with .htaccess protection is an excellent way to <em>secure</em> your <code>wp-config.php</code>.</p>
<h3 id="settings">Main Configuration Settings</h3>
<p>Now that <code>wp-config.php</code> is secure, it&rsquo;s time to add the required database information and then customize for optimum performance. This section covers the first four configuration settings that you&rsquo;ll find <em>already included</em> in your <code>wp-config.php</code>. Then in the next section, we&rsquo;ll explore some awesome techniques and really pimp things out.</p>
<h4>1) Database credentials</h4>
<p>The first and only <em>required</em> step is to add your database credentials. This should appear after the PHP comments near the top of the file:</p>
<pre><code>// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_name_here');

/** MySQL database username */
define('DB_USER', 'username_here');

/** MySQL database password */
define('DB_PASSWORD', 'password_here');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');</code></pre>
<p>For most servers, you&rsquo;ll need only the first three bits of information: database name, username and password. If WordPress can&rsquo;t connect after that, then you may need to change the hostname to whatever your host tells you. Only fiddle with the last two items &ndash; charset and collate &ndash; if you have need and know what you&rsquo;re doing.</p>
<h4>2) Authentication Unique Keys and Salts</h4>
<p>Next up is a section for key/salt definitions. By default it looks like this:</p>
<pre><code>/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');

/**#@-*/</code></pre>
<p>The eight definitions should be replaced with values generated via the official <a href="https://api.wordpress.org/secret-key/1.1/salt/">WordPress.org secret-key service</a>. Visit that link, refresh the page a few times, and paste the results into place, like so:</p>
<pre><code>/**#@+
 * Authentication Unique Keys and Salts.
 *
 * Change these to different unique phrases!
 * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 *
 * @since 2.6.0
 */
define('AUTH_KEY',         ')` 4yDGc w=*:l8@RD167k0+/+@+rgo(mI-x&lt;_~.=WtCm[qD8&lt;3S)TsR}K~bMLNT');
define('SECURE_AUTH_KEY',  'zO?htRkV.k[vBqn&lt;+.,lorpObkc?@|Vi+8`w=A9,|FjPB&amp;5`5|9&lt;[&amp;&amp;WaUB.pwTS');
define('LOGGED_IN_KEY',    'jtr|J-/.-:6CVh*8h.~bNzc3^#A9@hB9G3E/fx/&gt;k)pmTHbES5^Rq(+EINCW w&gt;8');
define('NONCE_KEY',        'O2Vz+br+`6MqQVv1{-g}sy -CF8M/tldEyWV[W}dnebd7m$6.P,m+.G6Ec]{V@Kl');
define('AUTH_SALT',        '&gt;x,, 8wMLIJCH}i94Ib+}~lR%r_))x@LU3~YJwCok++xaSVE@[My(zAg!Fpi4{NR');
define('SECURE_AUTH_SALT', '7[,gAJ#TQmsw:$!R-n-r%4&lt;UvG7%|-7&amp;jt4]XS-[KX&amp;O)|H,err]&lt;{EuFnmP3,M}');
define('LOGGED_IN_SALT',   '9dJP8uW2E2&amp;.^a|@I|[?qbY%z:&amp;jgnH&lt;OUg+t6Tks,Hox=M@~yx+b;~zU)436q=+');
define('NONCE_SALT',       '=Xv~8+!&gt;l:wy`~w0U-6wO2lmG8l5Xg21$J59T$T~)(h5m&lt;5`|/|dVN{j[80QMV60');

/**#@-*/</code></pre>
<p>Don&rsquo;t use the example keys shown here though &ndash; the whole idea is to specify <em>unique</em> phrases to <em>improve</em> security. And it&rsquo;s totally fine to replace these keys at any time &ndash; the worst that will happen is that currently logged-in users will need to log in again. </p>
<p>At this point, we have our database credentials and secret keys all ready to go. Next we want to <em>further improve security</em> by specifying a unique database prefix.</p>
<h4>3) WordPress Database Table prefix</h4>
<p>WordPress is a <em>huge</em> target for <a href="http://digwp.com/2010/07/wordpress-security-lockdown/#pharma-hack" title="WordPress Security Lockdown">malicious scripts</a>, <a href="http://digwp.com/2010/07/media-temple-wordpress-hack/" title="Media Temple WordPress Hack">hacks</a>, and <a href="http://digwp.com/2009/06/spam-link-injection-hacked/" title="Spam Link Injection Hacked (and How I Hopefully Fixed It)">spam</a>. One of the best ways to secure your WordPress database is to change the default table prefix. The default value, as seen below, is &ldquo;<code>wp_</code>&rdquo;:</p>
<pre><code>/**
 * WordPress Database Table prefix.
 *
 * You can have multiple installations in one database if you give each a unique
 * prefix. Only numbers, letters, and underscores please!
 */
$table_prefix  = 'wp_';
</code></pre>
<p>This works, but as the default value, it is heavily targeted by <a href="http://perishablepress.com/press/2009/12/22/protect-wordpress-against-malicious-url-requests/" title="Protect WordPress Against Malicious URL Requests">malicious scripts</a> and <a href="http://perishablepress.com/press/2010/07/14/blackhole-bad-bots/" title="Protect Your Site with a Blackhole for Bad Bots">bad bots</a>. Changing it to something <em>unique</em> essentially <em>immunizes</em> it against automated attacks on anything prefixed with <code>wp_</code>. The more <em>random and unique</em> the better, like a password: &ldquo;<code>h7G3vcDEo3jDf_</code>&rdquo; would be a good example. Note that ending the string with an underscore or some other easily recognizable character is a good way to keep things readable and easy to use.</p>
<h4>4) WordPress Localized Language</h4>
<p>By default WordPress uses the English language, but you can use any available language by following <a href="http://codex.wordpress.org/Installing_WordPress_in_Your_Language" title="Installing WordPress in Your Language">these steps</a>. As a part of that process, you&rsquo;ll specify your language in this part of the <code>wp-config.php</code> file:</p>
<pre><code>/**
 * WordPress Localized Language, defaults to English.
 *
 * Change this to localize WordPress.  A corresponding MO file for the chosen
 * language must be installed to wp-content/languages. For example, install
 * de.mo to wp-content/languages and set WPLANG to 'de' to enable German
 * language support.
 */
define ('WPLANG', '');</code></pre>
<p>It&rsquo;s pretty straightforward: if nothing is specified (as is seen here), English is used; otherwise, you include the <code>.mo</code> language file you are using for the translation.</p>
<h3 id="pimpin">Additional Tips and Tricks</h3>
<p>Now that you&rsquo;ve got the database connection, security keys, table prefix, and language definition dialed in you&rsquo;re ready to rock. Most WordPress sites are in great shape at this point, but there is <em>much</em> more that we can do with <code>wp-config.php</code> to maximize performance and make our lives easier.</p>
<h4>Pimping Post Revisions</h4>
<p>Recent versions of WordPress provides a post-revisioning system that enables users to save different versions of their blog posts and even revert to previously saved versions if necessary. Regardless of how much you do or do not despise this amazingly awesome feature, here are a couple of configurational definitions that may prove useful for you:</p>
<pre><code>// Limit the number of saved revisions
define('WP_POST_REVISIONS', 3); // any integer, but don't go crazy

// Disable the post-revisioning feature
define('WP_POST_REVISIONS', false); // kill the bloat</code></pre>
<h4>Specify the Autosave Interval</h4>
<p>In a similar vein as the post-revisioning feature is WordPress’ actually useful Autosave functionality. By default, WordPress saves your work every 60 seconds, but you can totally modify this setting to whatever you want. Don’t get too crazy though, unless you want to stress-out your server&nbsp;;)</p>
<pre><code>define('AUTOSAVE_INTERVAL', 160); // in seconds, don't go nuts</code></pre>
<h4>Automated Trash</h4>
<p>Since WordPress 2.9, we&rsquo;ve had the &ldquo;Trash&rdquo; feature to help prevent accidents. So now instead of deleting stuff like posts and comments, you send them to the Trash. By default WordPress deletes the Trash every 30 days, but you can set it to whatever you want by adding a line like this to <code>wp-config.php</code>:</p>
<pre><code>define('EMPTY_TRASH_DAYS', 7); // empty weekly</code></pre>
<p>To ride bareback without the safety net, you can disable the Trash feature by specifying a zero value:</p>
<pre><code>define('EMPTY_TRASH_DAYS', 0); // disable trash</code></pre>
<p>By disabling Trash, you&rsquo;ll be deleting stuff permanently the first time, just like way back in the day.</p>
<h4>Automatic Database Repair</h4>
<p>WordPress 2.9 also gave us automatic database repair, which enables you to repair and optimize your database even when not logged in. This functionality should be used on an <em>as-needed</em> basis by first adding the following snippet to <code>wp-config.php</code>:</p>
<pre><code>define('WP_ALLOW_REPAIR', true);</code></pre>
<p>With that in place, visit the following <abbr title="Uniform Resource Locator">URL</abbr> to open the &ldquo;Database Repair&rdquo; page:</p>
<p><code>http://example.com/wp-admin/maint/repair.php</code></p>
<p>There you&rsquo;ll be able to optimize and repair your database without needing to log in to WordPress. Important: While you have  <code>WP_ALLOW_REPAIR</code> set in <code>wp-config.php</code>, the Database Repair page is openly accessible by anyone who finds it. So definitely remove the line to disable the auto-repair functionality after you are done using it.</p>
<h4>Block External Requests</h4>
<p>If you need to prevent WordPress from making external requests, add this snippet to <code>wp-config.php</code>:</p>
<pre><code>define('WP_HTTP_BLOCK_EXTERNAL', true);</code></pre>
<p>This will prevent things from happening that normally happen, like updates, dashboard feeds, and data reporting. Fortunately, it&rsquo;s easy to whitelist (<em>allow</em> access) anything that is needed. Here is an example where we grant access to pingomatic.com:</p>
<pre><code>define('WP_ACCESSIBLE_HOSTS', 'rpc.pingomatic.com');</code></pre>
<h4>Blog Address and Site Address</h4>
<p>By default, these two configurational definitions are not included in the <code>wp-config.php</code> file, but they may be added to improve performance. These two settings were introduced in WordPress version 2.2 and override the database value without actually changing them. Example:</p>
<pre><code>define('WP_HOME', 'http://digwp.com'); // no trailing slash
define('WP_SITEURL', 'http://digwp.com');  // no trailing slash</code></pre>
<p>These settings should match those specified in your WordPress Admin. Once you set them in <code>wp-config.php</code>, they will be &ldquo;grayed-out&rdquo; when displayed in the Admin.</p>
<h4>Debugging WordPress</h4>
<p>Since WordPress version 2.3.1, users have been able to display certain errors and warnings to help with the debugging of their site. As of WordPress version 2.5, enabling error reporting raises the reporting level to <code>E_ALL</code> and activates warnings for deprecated functions. By default (i.e., if no definition is specified in the <code>wp-config.php</code> file), error reporting is disabled.</p>
<pre><code>define('WP_DEBUG', true); // debugging mode: 'true' = enable; 'false' = disable</code></pre>
<p>Adding that snippet to <code>wp-config.php</code> tells WordPress to display warnings and error messages with your web pages. This functionality is <em>extremely useful</em> but infrequently used by plugin and theme developers. If you&rsquo;ve never enabled debugging, you&rsquo;re in for a surprise &ndash; lots of errors even with some of the most popular plugins.</p>
<h4>Error Log Configuration</h4>
<p>Here is an easy way to enable basic error logging for your WordPress-powered site. Create a file called <code>php_error.log</code>, make it server-writable, and place it in the directory of your choice. Then edit the path in the third line of the following code and place into your <code>wp-config.php</code>:</p>
<pre><code>@ini_set('log_errors','On');
@ini_set('display_errors','Off');
@ini_set('error_log','/home/path/domain/logs/php_error.log');</code></pre>
<p>Error logs are powerful tools for keeping an eye on things and expediently resolving issues. It&rsquo;s awesome that WordPress makes this so easy. We cover this in greater depth along with a couple of other methods in <a href="http://digwp.com/2009/07/monitor-php-errors-wordpress/" title="3 Ways to Monitor PHP Errors">this post</a>.</p>
<h4>Increase PHP Memory</h4>
<p>If you are receiving error messages telling you that your &ldquo;Allowed memory size of xxx bytes exhausted,&rdquo; this setting may help resolve the issue. As of WordPress version 2.5, the <code>WP_MEMORY_LIMIT</code> definition enables you to specify the maximum amount of memory that may be used by PHP. Here are some examples:</p>
<pre><code>define('WP_MEMORY_LIMIT', '64M');
define('WP_MEMORY_LIMIT', '96M');
define('WP_MEMORY_LIMIT', '128M');</code></pre>
<p>By default, WordPress will automatically attempt to increase PHP memory up to 32MB, so this setting is only needed for values higher than 32MB. Note that some web hosts disable your ability to increase PHP memory, so you may need to ask (or beg) for them to do it.</p>
<h3>More info, tips and tricks for wp-config</h3>
<p>For more information on the <code>wp-config.php</code> file, <a href="http://codex.wordpress.org/Editing_wp-config.php" title="Editing wp-config.php">check out the WordPress Codex</a>. We also have some <a href="http://digwp.com/2009/06/wordpress-configuration-tricks/" title="WordPress Configuration Tricks">awesome wp-config tricks</a> and <a href="http://digwp.com/2009/07/optimize-wordpress-performance-with-the-wp-config-php-file/" title="Optimize WordPress Performance with the wp-config.php File">wp-config optimization tips</a> for your WordPress enjoyment :)</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/08/pimp-your-wp-config-php/">Permalink</a> | <a href="http://digwp.com/2010/08/pimp-your-wp-config-php/#comments">37 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/08/pimp-your-wp-config-php/&title=Pimp your&nbsp;wp-config.php">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/performance/" rel="tag">performance</a>, <a href="http://digwp.com/tag/security/" rel="tag">Security</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/08/pimp-your-wp-config-php/feed/</wfw:commentRss>
		<slash:comments>37</slash:comments>
		</item>
		<item>
		<title>Shortcode for&#160;Includes</title>
		<link>http://digwp.com/2010/06/shortcode-for-includes/</link>
		<comments>http://digwp.com/2010/06/shortcode-for-includes/#comments</comments>
		<pubDate>Mon, 28 Jun 2010 09:08:19 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[content]]></category>
		<category><![CDATA[include]]></category>
		<category><![CDATA[shortcode]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2365</guid>
		<description><![CDATA[One thing that WordPress doesn&#8217;t have the ability to do &#8220;out-of-the-box&#8221; is do includes, in the sense of including the content of one post into the content of another post directly in the post editor. For the umpteenth time around here, shortcodes to the rescue! This issue came up while my co-worker Tim at Wufoo [...]]]></description>
			<content:encoded><![CDATA[<p>One thing that WordPress doesn&#8217;t have the ability to do &#8220;out-of-the-box&#8221; is do <em>includes</em>, in the sense of including the content of one post into the content of another post directly in the post editor. For the <a href="http://digwp.com/tag/shortcode/">umpteenth time</a> around here, shortcodes to the rescue! </p>
<p><span id="more-2365"></span></p>
<p>This issue came up while my co-worker Tim at <a href="http://wufoo.com">Wufoo</a> was documenting parts of the latest <a href="http://wufoo.com/docs/api/v3/">Wufoo API</a>. Some of the API pages have areas on them that are exactly the same as other pages, for example, a chunk of navigation that links to other pages of documentation.</p>
<p>One possible way to deal with this is to make a special template just for these pages and include that chunk inside that template. This solution edges on the issue of template-bloat which I&#8217;ve been thinking a lot about lately. Creating a new template every time you need one little change is solving the problem with a sledgehammer rather than a scalpel. </p>
<p>The ideal solution is just to make a shortcode. You pass the ID of the post (in our case, page) that you want to include and the shortcode is replaced with that content. This is the usage, where XXXX would be the ID of the post:</p>
<pre><code>[digwp_include postidparam=XXXX]</code></pre>
<p>To make it work, we&#8217;ll add a fairly simple function to the functions.php file in our theme. The function will take the parameter, run a query for it, and return back the content if it finds any:</p>
<pre><code>function digwp_includeContentShortcode($atts) {
  
  $thepostid = intval($atts[postidparam]);
  $output = '';

  query_posts("p=$thepostid&amp;post_type=page");
  if (have_posts()) : while (have_posts()) : the_post();
    $output .= get_the_content($post-&gt;ID);
  endwhile; else:
    // failed, output nothing
  endif;
  wp_reset_query();

  return $output;

}

// USAGE
// In the post content, you can use [digwp_include postidparam="1234"]
// "1234" would be the WordPress ID of the Page you are trying to include

add_shortcode("digwp_include", "digwp_includeContentShortcode");</code></pre>
<p>Now you can publish small modules of content, and include them on any Post/Page that needs them! I&#8217;d probably create a Page on your site called like &#8220;Includes&#8221; or &#8220;Modules&#8221; and post them as Pages with that as the Parent Page. That way you don&#8217;t clutter up the root and they all stay organized together. </p>
<p>Check out this graphic (click for full size), which hopefully will drive home the idea:</p>
<p><a href="http://digwp.com/wp-content/blog-images/20100621-qgt1km86je73ci7ikwjpp3bexw.png"><img src="http://digwp.com/wp-content/blog-images/_20100621-qgt1km86je73ci7ikwjpp3bexw.png" width="570" height="442" alt="" title=""  /></a></p>
<p>Random notes: </p>
<ul>
<li>This is similar to the <a href="http://digwp.com/2010/01/custom-query-shortcode/">custom loop shortcode</a> I previously published.</li>
<li>This may be good territory for a plugin rather than functions.php code as I have done.</li>
<li>Notice the function is <a href="http://www.andrewnacin.com/2010/05/11/in-wordpress-prefix-everything/">properly prefixed</a>.</li>
</ul>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/06/shortcode-for-includes/">Permalink</a> | <a href="http://digwp.com/2010/06/shortcode-for-includes/#comments">28 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/06/shortcode-for-includes/&title=Shortcode for&nbsp;Includes">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/content/" rel="tag">content</a>, <a href="http://digwp.com/tag/include/" rel="tag">include</a>, <a href="http://digwp.com/tag/shortcode/" rel="tag">shortcode</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/06/shortcode-for-includes/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
		<item>
		<title>Show Post Thumbnails in&#160;Feeds</title>
		<link>http://digwp.com/2010/06/show-post-thumbnails-in-feeds/</link>
		<comments>http://digwp.com/2010/06/show-post-thumbnails-in-feeds/#comments</comments>
		<pubDate>Tue, 08 Jun 2010 07:05:49 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[feeds]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[thumbnails]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=2308</guid>
		<description><![CDATA[One of the nice things about using WordPress&#8217; new post-thumbnails feature is that they provide tons of flexibility in terms of where and how you display your post thumbnails. By design, post thumbnails are not included within post content, so they will not be displayed in your blog posts unless you call them specifically with [...]]]></description>
			<content:encoded><![CDATA[<p>One of the nice things about using WordPress&rsquo; new post-thumbnails feature is that they provide tons of flexibility in terms of <em>where</em> and <em>how</em> you display your post thumbnails. By design, post thumbnails are not included within post content, so they will not be displayed in your blog posts unless you call them specifically with the proper template tag:</p>
<pre><code>&lt;?php the_post_thumbnail(); ?&gt;</code></pre>
<p>When included within the loop, <code>the_post_thumbnail()</code> will output the markup for the post&rsquo;s thumbnail, linked to a full-size or pre-sized version of the image. Of course, there are a <a href="http://wpengineer.com/the-ultimative-guide-for-the_post_thumbnail-in-wordpress-2-9/" title="The Ultimative Guide For the_post_thumbnail In WordPress 2.9">few more awesome things</a> that you can do with <a href="http://codex.wordpress.org/Template_Tags/the_post_thumbnail" title="WordPress Codex: Template Tags/the_post_thumbnail">the_post_thumbnail</a>. Now that we&rsquo;ve seen how to include thumbnails in <em>post</em> content, let&rsquo;s do it for <em>feed</em> content..</p>
<p><span id="more-2308"></span></p>
<h3>Display Post Thumbnails in Feed Content</h3>
<p>To include post-thumbnails in your feeds, we need to filter WordPress&rsquo; feed functionality and inject the required template tag into both <em>feed-excerpt</em> and <em>full-feed</em> content:</p>
<pre><code>// show post thumbnails in feeds
function diw_post_thumbnail_feeds($content) {
	global $post;
	if(has_post_thumbnail($post-&gt;ID)) {
		$content = '&lt;div&gt;' . get_the_post_thumbnail($post-&gt;ID) . '&lt;/div&gt;' . $content;
	}
	return $content;
}
add_filter('the_excerpt_rss', 'diw_post_thumbnail_feeds');
add_filter('the_content_feed', 'diw_post_thumbnail_feeds');</code></pre>
<p>Include that code in your active theme&rsquo;s <code>functions.php</code> file and your feeds will display the post thumbnail <em>before</em> each post. To display the post thumbnail <em>after</em> the post content, a slight adjustment is made to the fourth line of the function:</p>
<p><code>$content = $content . '&lt;div&gt;' . get_the_post_thumbnail($post-&gt;ID) . '&lt;/div&gt;';</code></p>
<p>The <code>&lt;div&gt;</code> will prevent the post text from wrapping around the post thumbnail, but theoretically its removal would enable the post content to wrap around the image:</p>
<p><code>$content = get_the_post_thumbnail($post-&gt;ID) . $content;</code></p>
<p>As easy and flexible as it is working with <code>the_post_thumbnail()</code>, there may be situations where you need more control over the appearance and functionality of your posts&rsquo; attached images. Fortunately, <a href="http://perishablepress.com/press/2008/12/22/wordpress-custom-fields-tips-tricks/" title="WordPress Custom Fields, Part II: Tips and Tricks">WordPress&rsquo; custom fields</a> and <a href="http://digwp.com/2009/08/awesome-image-attachment-recipes-for-wordpress/" title="Awesome Image-Attachment Recipes for WordPress">image-attachment functionality</a> enable just about any custom configuration you can imagine.</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/06/show-post-thumbnails-in-feeds/">Permalink</a> | <a href="http://digwp.com/2010/06/show-post-thumbnails-in-feeds/#comments">16 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/06/show-post-thumbnails-in-feeds/&title=Show Post Thumbnails in&nbsp;Feeds">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/feeds/" rel="tag">feeds</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/thumbnails/" rel="tag">thumbnails</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/06/show-post-thumbnails-in-feeds/feed/</wfw:commentRss>
		<slash:comments>16</slash:comments>
		</item>
		<item>
		<title>Next/Previous Post Navigation Outside of the WordPress&#160;Loop</title>
		<link>http://digwp.com/2010/04/post-navigation-outside-loop/</link>
		<comments>http://digwp.com/2010/04/post-navigation-outside-loop/#comments</comments>
		<pubDate>Fri, 23 Apr 2010 12:50:50 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[posts]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1975</guid>
		<description><![CDATA[WordPress provides several navigational template tags to make it easy for visitors to surf your pages. There are basically two different types of template tags used for chronological post navigation: posts_nav_link() &#8211; for navigating various archive (non-single) pages previous_post_link() &#38; next_post_link() &#8211; for navigating single-post pages These template tags output the HTML markup required to [...]]]></description>
			<content:encoded><![CDATA[<p>WordPress provides several <a href="http://digwp.com/2009/08/wordpress-page-navigation/" title="Definitive Guide to WordPress Page Navigation">navigational template tags</a> to make it easy for visitors to surf your pages. There are basically two different types of template tags used for chronological post navigation:</p>
<ul>
<li><code>posts_nav_link()</code> &ndash; for navigating various archive (non-single) pages</li>
<li><code>previous_post_link()</code> &amp; <code>next_post_link()</code> &ndash; for navigating single-post pages</li>
</ul>
<p>These template tags output the <acronym title="Hypertext Markup Language">HTML</acronym> markup required to create the actual hyperlinks that will appear on your web pages. By default, navigation links for single pages display the title of adjacent posts, while those for archive pages display &ldquo;Next-Page&rdquo; and &ldquo;Previous-Page&rdquo;.</p>
<p>Of course, the default text, link-position, and just about everything else can be <a href="http://digwp.com/2009/12/optimizing-wordpress-post-navigation/" title="Optimizing WordPress Post Navigation">customized and optimized</a> according to your specific needs.</p>
<p><span id="more-1975"></span></p>
<p>Normally, WordPress&rsquo; navigational template tags appear within the loop:</p>
<div id="post_1975">
<pre><code>&lt;?php get_header(); ?&gt;

	&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

		&lt;h1&gt;&lt;?php the_title(); ?&gt;&lt;/h1&gt;
		&lt;?php the_content(); ?&gt;

	&lt;?php endwhile; ?&gt;

		&lt;p class="nav"&gt;&lt;?php posts_nav_link(); ?&gt;&lt;/p&gt;

	&lt;?php else : ?&gt;

		&lt;h1&gt;Nothing Found&lt;/h1&gt;
		&lt;p&gt;Please try a little harder next time..&lt;/p&gt;

	&lt;?php endif; ?&gt;

&lt;?php get_footer(); ?&gt;</code></pre>
</div>
<p>This code is typical for <code>index.php</code> and other &ldquo;Archive-View&rdquo; pages, such as for Categories, Tags, Search Results, and so on. Similar code is used for Single Page-Views, where <code>single.php</code> would replace the <code>posts_nav_link()</code>&nbsp;<sup>1</sup> template tag for <code>previous_post_link()</code> and <code>next_post_link()</code> tags.</p>
<p>The navigational template tags are generally placed between the <code>endwhile</code> and <code>else</code>&nbsp;<sup>2</sup> statements, along with stuff like post comments, meta information, and social-media links. Within this section of the loop, code is processed only once, as opposed to multiple times in the first part of the loop.</p>
<h3>Navigation <em>outside</em> of the loop</h3>
<p>The good news is that the template tag for archive-view navigation (i.e., non-single pages) seems to work just fine outside of the loop. So you can just place <code>posts_nav_link()</code> anywhere within your theme template.</p>
<p>Then, to include <strong>single-view</strong> navigation outside of the loop, we can use <code>query_posts</code> to substantiate the loop anywhere within your <code>single.php</code> file. Here is a simplified version of the code that I am using at <a href="http://perishablepress.com/" title="Digital Design and Dialogue">Perishable Press</a>:</p>
<pre><code>&lt;?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

	&lt;?php previous_post_link(); ?&gt; | &lt;?php next_post_link(); ?&gt;

&lt;?php endwhile; endif; ?&gt;</code></pre>
<p>That&rsquo;s all there is to it, really. A nice trick to have in the hat. Then, we can take it a step further and consolidate both types of page navigation (single and archive) in a single chunk of code:</p>
<pre><code>&lt;?php if(is_single()) { // single-view navigation ?&gt;

	&lt;?php $posts = query_posts($query_string); if (have_posts()) : while (have_posts()) : the_post(); ?&gt;

		&lt;?php previous_post_link(); ?&gt; | &lt;?php next_post_link(); ?&gt;

	&lt;?php endwhile; endif; ?&gt;

&lt;?php } else { // archive view navigation ?&gt;

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

&lt;?php } ?&gt;</code></pre>
<p>This code displays the appropriate template tags for both single-page-views and archive-views. If placed in its own file named &ldquo;<code>nav.php</code>&rdquo;, including it within your theme files is as simple as a template tag:</p>
<pre><code>&lt;?php include_once("nav.php"); ?&gt;</code></pre>
<p>That&rsquo;s an easy way to get your Next/Previous page navigation working anywhere outside the loop. This could easily be made into 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 function</a> for your theme&rsquo;s <a href="http://digwp.com/2010/04/wordpress-custom-functions-php-template-part-2/" title="WordPress Custom functions.php Template, Part 2">functions.php file</a>. Or maybe even <a href="http://digwp.com/2010/03/add-plugin-to-wordpress-plugin-repository/" title="How to Add Your Plugin to the WordPress Plugin Directory">a plugin</a>..?&nbsp;;)</p>
<p>For more information on WordPress Page Navigation, check out these fine <acronym title="Digging into WordPress">DiW</acronym> articles:</p>
<ul>
<li><a href="http://digwp.com/2009/08/wordpress-page-navigation/">Definitive Guide to WordPress Page Navigation</a></li>
<li><a href="http://digwp.com/2009/12/optimizing-wordpress-post-navigation/">Optimizing WordPress Post Navigation</a></li>
</ul>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/post-navigation-outside-loop/">Permalink</a> | <a href="http://digwp.com/2010/04/post-navigation-outside-loop/#comments">15 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/04/post-navigation-outside-loop/&title=Next/Previous Post Navigation Outside of the WordPress&nbsp;Loop">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/design/" title="View all posts in Design" rel="category tag">Design</a>, <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/navigation/" rel="tag">navigation</a>, <a href="http://digwp.com/tag/posts/" rel="tag">posts</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/post-navigation-outside-loop/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Call a Widget with a&#160;Shortcode</title>
		<link>http://digwp.com/2010/04/call-widget-with-shortcode/</link>
		<comments>http://digwp.com/2010/04/call-widget-with-shortcode/#comments</comments>
		<pubDate>Mon, 12 Apr 2010 17:30:03 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1752</guid>
		<description><![CDATA[We covered how to run a shortcode in a widget. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably [...]]]></description>
			<content:encoded><![CDATA[<p>We covered how to <a href="http://digwp.com/2010/03/shortcodes-in-widgets/">run a shortcode in a widget</a>. But what about inserting a widget with a shortcode? I recently had this situation come up. I had a single page where I just wanted to be able to chuck in a widget without the whole rigmarole of creating a special widgetized area and probably a custom page template for that widgetized area and such. I wanted to just put [widget widget_name="my_widget"] in the pages content and have that widget pop in. Turns out it wasn&#8217;t as easy I wanted it to be, but it&#8217;s not that bad&#8230;</p>
<p><span id="more-1752"></span></p>
<p>The answer was creating a custom function for the functions.php file which would output any widget by name. There is a function just for that: <code>the_widget()</code> (<a href="http://codex.wordpress.org/Template_Tags/the_widget">incomplete codex page</a>).</p>
<h3>The logic</h3>
<ol>
<li>Test if widget exists</li>
<li>If it does&#8230;
<ol>
<li>Start capturing output</li>
<li>Output widget</li>
<li>End capturing output</li>
<li>Return captured output</li>
</ol>
</li>
<li>If it doesn&#8217;t exist&#8230;
<ol>
<li>Output fail message</li>
</ol>
</li>
</ol>
<h3>The code for functions.php</h3>
<pre><code>function widget($atts) {
    
    global $wp_widget_factory;
    
    extract(shortcode_atts(array(
        'widget_name' =&gt; FALSE
    ), $atts));
    
    $widget_name = wp_specialchars($widget_name);
    
    if (!is_a($wp_widget_factory-&gt;widgets[$widget_name], 'WP_Widget')):
        $wp_class = 'WP_Widget_'.ucwords(strtolower($class));
        
        if (!is_a($wp_widget_factory-&gt;widgets[$wp_class], 'WP_Widget')):
            return '&lt;p&gt;'.sprintf(__("%s: Widget class not found. Make sure this widget exists and the class name is correct"),'&lt;strong&gt;'.$class.'&lt;/strong&gt;').'&lt;/p&gt;';
        else:
            $class = $wp_class;
        endif;
    endif;
    
    ob_start();
    the_widget($widget_name, $instance, array('widget_id'=&gt;'arbitrary-instance-'.$id,
        'before_widget' =&gt; '',
        'after_widget' =&gt; '',
        'before_title' =&gt; '',
        'after_title' =&gt; ''
    ));
    $output = ob_get_contents();
    ob_end_clean();
    return $output;
    
}
add_shortcode('widget','widget'); </code></pre>
<h3>Usage</h3>
<p>Now in Post/Page content, you can use the widget just by referencing it by name:</p>
<pre><code>[widget widget_name="Your_Custom_Widget"]</code></pre>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/">Permalink</a> | <a href="http://digwp.com/2010/04/call-widget-with-shortcode/#comments">15 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/04/call-widget-with-shortcode/&title=Call a Widget with a&nbsp;Shortcode">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/04/call-widget-with-shortcode/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Remove/Replace Content from the WordPress&#160;Database</title>
		<link>http://digwp.com/2010/03/remove-replace-content-wordpress-database/</link>
		<comments>http://digwp.com/2010/03/remove-replace-content-wordpress-database/#comments</comments>
		<pubDate>Tue, 30 Mar 2010 09:56:42 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[nofollow]]></category>
		<category><![CDATA[sql]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1643</guid>
		<description><![CDATA[A useful tool to have in in your WordPress toolbelt is the ability to quickly and easily search for, find, and replace specific strings of text directly from the MySQL database. We can do this by entering SQL queries either directly or through one of those handy interface applications like phpMyAdmin, which seems like one [...]]]></description>
			<content:encoded><![CDATA[<p>A useful tool to have in in your WordPress toolbelt is the ability to quickly and easily <em>search</em> for, <em>find</em>, and <em>replace</em> specific strings of text directly from the <acronym title="(My) Structured Query Language">MySQL</acronym> database. We can do this by entering <acronym title="Structured Query Language">SQL</acronym> queries either directly or through one of those handy interface applications like <a href="http://www.phpmyadmin.net/">phpMyAdmin</a>, which seems like one of the most prevalent <acronym title="PHP: Hypertext Preprocessor">PHP</acronym> applications on servers today.</p>
<p>Hopefully, you have some experience working <em>directly</em> with the database, but even if you&rsquo;re new to it, the simple recipes presented in this <acronym title="Digging into WordPress">DiW</acronym> article will help you find, replace, and delete specific text content using a few simple <acronym title="Structured Query Language">SQL</acronym> commands. This gives you incredible power to make sitewide changes to your posts, comments, or any other database table with a few simple clicks.</p>
<p><span id="more-1643"></span></p>
<p>Before we get started, remember to</p>
<blockquote><p>backup your database before making any changes!</p></blockquote>
<p>Once we&rsquo;ve got our database backup(s), we&rsquo;re ready to dig into some easy, effective <acronym title="Structured Query Language">SQL</acronym> queries for manipulating post content. To give us some context while we go, we&rsquo;ll assume a hypothetical case: let&rsquo;s say we want to find and remove all instances of the <a href="http://digwp.com/2010/02/remove-nofollow-attributes-from-post-content/" title="WordPress Tip: Remove nofollow Attributes from Post Content">mystical nofollow attribute</a>, in all of its various incarnations:</p>
<ul>
<li><code>rel="nofollow"</code></li>
<li><code>rel="external nofollow"</code></li>
<li><code>rel="nofollow external"</code></li>
</ul>
<p>In addition to these instances of the attribute, our custom query will also match any instances of other attribute values besides &ldquo;<code>external</code>&rdquo;. A couple of things to keep in mind about <acronym title="Structured Query Language">SQL</acronym> selectors:</p>
<pre><code>%   =&gt; this is the "wildcard" selector - will match /any/ character
*   =&gt; this is the "all" selector - will match /all/ entries</code></pre>
<p>All right, let&rsquo;s look at some of the useful things we can do using a few custom <acronym title="Structured Query Language">SQL</acronym> queries..</p>
<h3>Display all instances of a given text string</h3>
<p>Before making any sitewide <em>changes</em> to your database, it&rsquo;s a good idea to simply search and find all instances of a given text string. So in our example, we are looking for three different <code>nofollow</code> patterns, as described above.</p>
<p>Using phpMyAdmin, click on the &ldquo;SQL&rdquo; tab and enter the following <acronym title="Structured Query Language">SQL</acronym> query:</p>
<pre><code>SELECT * FROM wp_posts WHERE ( 
post_content LIKE '% rel="nofollow"%'
OR post_content LIKE '% nofollow%'
OR post_content LIKE '%nofollow %'
);</code></pre>
<p>This query selects everything from the <code>wp_posts</code> table that matches any of our three target cases. Note that if you are <a href="http://digwp.com/2009/11/how-to-secure-your-new-wordpress-installation/" title="How to Secure Your New WordPress Installation">using a unique table prefix</a> (i.e., anything other than &ldquo;<code>wp_</code>&rdquo;), you will need to change the &ldquo;<code>wp_posts</code>&rdquo; in the first line to match.</p>
<p>From here, you can check the results by evaluating the overall number of posts and &ldquo;zooming in&rdquo; on any specific post(s) of interest. To search for a text string in a <em>different</em> table, replace &ldquo;<code>wp_posts</code>&rdquo; with something else, such as &ldquo;<code>wp_comments</code>&rdquo; or whatever you like.</p>
<p>If desired, we could locate all instances of each specific pattern individually using each of the following queries:</p>
<pre><code>SELECT * FROM wp_posts WHERE (post_content LIKE '%nofollow %');
SELECT * FROM wp_posts WHERE (post_content LIKE '% nofollow%');
SELECT * FROM wp_posts WHERE (post_content LIKE '% rel="nofollow"%');</code></pre>
<p>So with our <code>nofollow</code> example, let&rsquo;s say we have 100 posts that contain some instance of the target string. We no longer want these attributes polluting our post content, so let&rsquo;s remove them..</p>
<h3>Remove all instances of a given text string</h3>
<p>Once we are ready to actually remove all instances of the target string in our post content, we run the following three queries, either all at once or one at a time:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'nofollow ', '' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' nofollow', '' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' rel="nofollow"', '' );</code></pre>
<p>Bam! Just like that, we have removed all of those silly <code>nofollow</code> attributes throughout our entire site <strong>without affecting anything else</strong>. It&rsquo;s as if they never existed in the first place. So much power!&nbsp;;)</p>
<p>How does it work? Easy: each command is saying, &ldquo;replace all matches in the <code>post_content</code> field with exactly nothing.&rdquo; As far as I know, there is no way to combine these queries into a single command, so if there are any <acronym title="Structured Query Language">SQL</acronym> wizards reading, please enlighten.</p>
<p>As you may guess, the general pattern for <strong>removing</strong> any text string from all post content in the database looks like this:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'text to be replaced', '' );</code></pre>
<p>And from here, we can just as easily <em>replace</em> any matching text..</p>
<h3>Replace all instances of a given text string</h3>
<p>Lastly, let&rsquo;s look at how to replace our text string with some different text. We&rsquo;re actually using the same query as in the previous section, only instead of empty quotes in the second argument, we&rsquo;re going to add our replacement text.</p>
<p>Let&rsquo;s say that, instead of deleting our <code>nofollow</code> attributes, we want to replace them with &ldquo;<strong>do</strong>follow&rdquo;. We wouldn&rsquo;t actually do this on a production site because <code>dofollow</code> is not a valid value for the <code>rel</code> attribute. But for the sake of our hypothetical, let&rsquo;s just do it anyway. Here&rsquo;s how it looks:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'nofollow ', 'dofollow ' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' nofollow', ' dofollow' );
UPDATE wp_posts SET post_content = REPLACE ( post_content, ' rel="nofollow', ' rel="dofollow' );</code></pre>
<p>Same idea as before, only now we can see that <em>anything</em> can be used for the replacement text, even imaginary attribute values&nbsp;;)</p>
<p>And finally, here is the general formula for <strong>replacing</strong> post content via <acronym title="Structured Query Language">SQL</acronym>:</p>
<pre><code>UPDATE wp_posts SET post_content = REPLACE ( post_content, 'text to be replaced', 'replacement text' );</code></pre>
<p>And of course keep in mind that this query may be modified as explained in the article to search for, remove, and replace any content &ndash; markup, text, special characters &ndash; in your WordPress database. For site admins and serious bloggers, this is an excellent way to speed up maintenance and get things done.</p>
<p>Of course, there&rsquo;s probably a plugin that will do all of this for you&nbsp;;)</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/">Permalink</a> | <a href="http://digwp.com/2010/03/remove-replace-content-wordpress-database/#comments">8 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/03/remove-replace-content-wordpress-database/&title=Remove/Replace Content from the WordPress&nbsp;Database">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/database/" rel="tag">database</a>, <a href="http://digwp.com/tag/nofollow/" rel="tag">nofollow</a>, <a href="http://digwp.com/tag/sql/" rel="tag">sql</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/remove-replace-content-wordpress-database/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Declare Multiple Widgetized&#160;Areas</title>
		<link>http://digwp.com/2010/03/declare-multiple-widgetized-areas/</link>
		<comments>http://digwp.com/2010/03/declare-multiple-widgetized-areas/#comments</comments>
		<pubDate>Thu, 18 Mar 2010 12:24:26 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1686</guid>
		<description><![CDATA[Have a bunch of different areas you wish to declare as a widgetized area? Save repetative code by creating a quick array of their names, then loop through that array calling the register_sidebar() function on each one. Elementary PHP stuff here, but hey, it just saved me quite a few lines of code in a [...]]]></description>
			<content:encoded><![CDATA[<p>Have a bunch of different areas you wish to declare as a widgetized area? Save repetative code by creating a quick array of their names, then loop through that array calling the register_sidebar() function on each one. Elementary PHP stuff here, but hey, it just saved me quite a few lines of code in a widget-heavy theme I am working on.</p>
<pre><code>if ( function_exists('register_sidebar') ) {

    $allWidgetizedAreas = array("Homepage Left", "Homepage Right", "Sidebar One", "Movies", "Admin");
    
    foreach ($allWidgetizedAreas as $WidgetAreaName) {
    
        register_sidebar(array(
           'name'=&gt; $WidgetAreaName,
           'before_widget' =&gt; '&lt;div id="%1$s" class="widget %2$s left half"&gt;',
           'after_widget' =&gt; '&lt;/div&gt;',
           'before_title' =&gt; '&lt;h3 class="widgettitle"&gt;',
           'after_title' =&gt; '&lt;/h3&gt;',
        ));
    
    }

}</code></pre>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/declare-multiple-widgetized-areas/">Permalink</a> | <a href="http://digwp.com/2010/03/declare-multiple-widgetized-areas/#comments">7 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/03/declare-multiple-widgetized-areas/&title=Declare Multiple Widgetized&nbsp;Areas">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/php/" rel="tag">PHP</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/declare-multiple-widgetized-areas/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Add Classes to&#160;post_class</title>
		<link>http://digwp.com/2010/03/add-classes-to-post_class/</link>
		<comments>http://digwp.com/2010/03/add-classes-to-post_class/#comments</comments>
		<pubDate>Fri, 12 Mar 2010 21:04:45 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[classes]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Theme]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1567</guid>
		<description><![CDATA[The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting: &#60;div &#60;?php post_class() ?&#62; id="post-&#60;?php the_ID(); ?&#62;"&#62; &#60;!-- Post stuff --&#62; &#60;/div&#62; I was in a circumstance where I wanted to add an additional class to what [...]]]></description>
			<content:encoded><![CDATA[<p>The post_class() function in WordPress is pretty darn useful. It is used like this, in most templates, in a wrapping div of all the content you are outputting:</p>
<pre><code>&lt;div &lt;?php post_class() ?&gt; id="post-&lt;?php the_ID(); ?&gt;"&gt;
   &lt;!-- Post stuff --&gt;
&lt;/div&gt;</code></pre>
<p>I was in a circumstance where I wanted to add an additional class to what that was outputting. My thought process went like this:</p>
<ol>
<li>Arg. I guess I&#8217;m going to have to write a function to filter the output of that function. Let&#8217;s begin the research.</li>
<li>Wait. I bet that function has an alternate that returns a string rather than echos it. I&#8217;ll just use that, and echo it out along with my own custom class.</li>
<li>Double wait. I bet those smart WordPress folks have thought of this&#8230;</li>
</ol>
<p><span id="more-1567"></span></p>
<h3>1. Filtering</h3>
<p>This kind of thing is generally beyond my comfort zone, but you&#8217;d basically write your own little function which takes in what the output would have been, add you own stuff to it, then return the new value.</p>
<p>Then call the new function with a filter in your functions.php file:</p>
<pre><code>add_filter('post_class','add_my_stuff');</code></pre>
<h3>2. Output exiting classes, then add yours</h3>
<p>Like most functions that echo stuff, there is a version that doesn&#8217;t echo stuff, in which &#8220;get_&#8221; prefaces the function name. I didn&#8217;t even have to look it up I just knew there would be. Since it&#8217;s a list, this function returns an array, so to output them, you&#8217;ll need to loop through the array:</p>
<pre><code>&lt;div class="&lt;?php $allClasses = get_post_class(); foreach ($allClasses as $class) { echo $class . " "; } ?&gt; group" id="post-&lt;?php the_ID(); ?&gt;"&gt;</code></pre>
<p>The cool part here is that is doesn&#8217;t add &#8220;class=&#8221; in the output, you can do that yourself, meaning that I can add my own classes after the output is finished.</p>
<h3>3. Built in&#8230;</h3>
<p>Of course, as it turns out, this is far easier than #2 made it out to be. To add additional classes, just pass them as a parameter!</p>
<pre><code>&lt;?php post_class('special'); ?&gt;</code></pre>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/">Permalink</a> | <a href="http://digwp.com/2010/03/add-classes-to-post_class/#comments">2 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/03/add-classes-to-post_class/&title=Add Classes to&nbsp;post_class">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/classes/" rel="tag">classes</a>, <a href="http://digwp.com/tag/functions/" rel="tag">functions</a>, <a href="http://digwp.com/tag/theme/" rel="tag">Theme</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/add-classes-to-post_class/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Shortcodes in&#160;Widgets</title>
		<link>http://digwp.com/2010/03/shortcodes-in-widgets/</link>
		<comments>http://digwp.com/2010/03/shortcodes-in-widgets/#comments</comments>
		<pubDate>Wed, 10 Mar 2010 13:07:32 +0000</pubDate>
		<dc:creator>Chris Coyier</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[shortcode]]></category>
		<category><![CDATA[widgets]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1560</guid>
		<description><![CDATA[I had occasion the other day to run a shortcode inside of a text widget. You know shortcodes&#8230; we talk about them all the time. They are keywords in [square brackets] that do something special. Sometimes something really simple like returning a string (so you can have a global location to change that string) or [...]]]></description>
			<content:encoded><![CDATA[<p>I had occasion the other day to run a shortcode inside of a text widget. You know shortcodes&#8230; we talk about them <a href="http://digwp.com/tag/shortcode/">all the time</a>. They are keywords in [square brackets] that do something special. Sometimes something really simple like returning a string (so you can have a global location to change that string) or something complicated like call a plugin that does something fancy like build a photo gallery.</p>
<p>But alas&#8230;</p>
<div class="image-wrap">
<img src="http://digwp.com/wp-content/blog-images/shortcodeinwidget.png" width="371" height="222" alt="" title="" /><br />
This ain&#8217;t gonna work &#8220;out-of-the-box&#8221;
</div>
<p><span id="more-1560"></span></p>
<p>After tinkering with some far-too-complicated solutions, someone on Twitter helped me with a deliciously simple solution: Just add this to your functions.php file:</p>
<pre><code>add_filter('widget_text', 'do_shortcode');</code></pre>
<p>This will ensure that the text content of widgets is parsed for shortcodes and those shortcodes are ran. Awesome.</p>
<p>Stephanie Leary wrote a great article on <a href="http://sillybean.net/wordpress/content/using-shortcodes-everywhere/">Using Shortcodes Everywhere</a>, which covers this as well as using shortcodes in a bunch of other places: Comments, templates, excerpts, etc.</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/03/shortcodes-in-widgets/">Permalink</a> | <a href="http://digwp.com/2010/03/shortcodes-in-widgets/#comments">4 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/03/shortcodes-in-widgets/&title=Shortcodes in&nbsp;Widgets">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/shortcode/" rel="tag">shortcode</a>, <a href="http://digwp.com/tag/widgets/" rel="tag">widgets</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/03/shortcodes-in-widgets/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Display Separate Counts for Comments, Pingbacks and&#160;Trackbacks</title>
		<link>http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/</link>
		<comments>http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/#comments</comments>
		<pubDate>Wed, 24 Feb 2010 09:43:48 +0000</pubDate>
		<dc:creator>Jeff Starr</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[comments]]></category>
		<category><![CDATA[tips]]></category>
		<category><![CDATA[tricks]]></category>

		<guid isPermaLink="false">http://digwp.com/?p=1452</guid>
		<description><![CDATA[In WordPress, there are three ways to respond to a post: you can leave a comment, leave a trackback, or just link to the post to create a pingback. When displaying all of the responses to your posts, it&#8217;s a good idea to separate the comments from the pingbacks and trackbacks. Uninterrupted comment threads are [...]]]></description>
			<content:encoded><![CDATA[<p>In WordPress, there are three ways to respond to a post: you can leave a comment, leave a trackback, or just link to the post to create a pingback. When displaying all of the responses to your posts, it&rsquo;s a good idea to separate the comments from the pingbacks and trackbacks. Uninterrupted comment threads are a pleasure to read, as are well-styled lists of pingbacks. This is an excellent way to improve the usability, organization, and stylishness of your comment areas. </p>
<p>In this <acronym title="Digging into WordPress">DiW</acronym> tutorial, you&rsquo;ll learn how to separate your responses and display the comment count for each type. Here is a diagram to help visual the goal:</p>
<p><img src="http://digwp.com/wp-content/blog-images/comments-pingbacks.gif" alt="[ Separated display of comments, pingbacks and trackbacks ]" /></p>
<p><span id="more-1452"></span></p>
<p>As you can see, separating these lists gives us a cleaner comments area, making things easier for everyone. Even better news is that we&rsquo;re going to set it up in <strong>two steps</strong>. If you would rather group the pingbacks and trackbacks and just segregate the comments, just a few tweaks and you&rsquo;re off to the races.</p>
<p>First let&rsquo;s see how to separate everything, then explain the grouping of pingbacks and trackbacks before wrapping things up.</p>
<h3>Step 1 &#8211; Display separate comments, pingbacks, and trackbacks</h3>
<p>The first thing we need to do is separate the different response types. Fortunately, WordPress makes this very easy. First, open your them&rsquo;s <code>single.php</code> file and use the following template tag to call your <code>comments.php</code> template:</p>
<pre><code>comments_template('/comments.php',true);</code></pre>
<p>This code will enable WordPress to segregate and count each of the different response types using the <code>$wp_query</code> object. Now let&rsquo;s separate the comments, pingbacks, and trackbacks. In your <code>comments.php</code> file, use the following code as your comments loop:</p>
<pre><code>&lt;?php if (!empty($comments_by_type['comment'])) { ?&gt;

	&lt;h3 id="comments"&gt;Comments&lt;h3&gt;
	&lt;ol class="commentlist"&gt;
		&lt;?php wp_list_comments('type=comment'); ?&gt;
	&lt;/ol&gt;

&lt;?php } if (!empty($comments_by_type['pingback'])) { ?&gt;

	&lt;h3 id="pingbacks"&gt;Pingbacks&lt;/h3&gt;
	&lt;ol class="pingbacklist"&gt;
		&lt;?php wp_list_comments('type=pingback'); ?&gt;
	&lt;/ol&gt;

&lt;?php } if (!empty($comments_by_type['trackback'])) { ?&gt;

	&lt;h3 id="trackbacks"&gt;Trackbacks&lt;/h3&gt;
	&lt;ol class="trackbacklist"&gt;
		&lt;?php wp_list_comments('type=trackback'); ?&gt;
	&lt;/ol&gt;

&lt;?php } ?&gt;</code></pre>
<p>This symmetrical slice of code will output the following markup, assuming that the post actually has all three types of responses:</p>
<pre><code>&lt;h3 id="comments"&gt;Comments&lt;h3&gt;
&lt;ol class="commentlist"&gt;
	&lt;li&gt;Comment #1 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Comment #2 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Comment #3 - Blah blah blah..&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="pingbacks"&gt;Pingbacks&lt;/h3&gt;
&lt;ol class="pingbacklist"&gt;
	&lt;li&gt;Pingback #1 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Pingback #2 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Pingback #3 - Blah blah blah..&lt;/li&gt;
&lt;/ol&gt;
&lt;h3 id="trackbacks"&gt;Trackbacks&lt;/h3&gt;
&lt;ol class="trackbacklist"&gt;
	&lt;li&gt;Trackback #1 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Trackback #2 - Blah blah blah..&lt;/li&gt;
	&lt;li&gt;Trackback #3 - Blah blah blah..&lt;/li&gt;
&lt;/ol&gt;</code></pre>
<p>When one of the different response types doesn&rsquo;t exist on the post, that section will simply be omitted from the markup, keeping things nice and clean. </p>
<h3>Step 2 &#8211; Display separate response counts</h3>
<p>Now, to display the count for each of these response types, we can call upon the <code>$wp_query</code> object to retrieve and echo the information:</p>
<pre><code>&lt;?php echo count($wp_query-&gt;comments_by_type['comments']); ?&gt;
&lt;?php echo count($wp_query-&gt;comments_by_type['pingback']); ?&gt;
&lt;?php echo count($wp_query-&gt;comments_by_type['trackback']); ?&gt;</code></pre>
<p>Each of these lines displays a number corresponding to a specific response type. These response counts may be integrated into our previous code to give us the final result:</p>
<pre><code>&lt;?php if (have_comments()) : global $wp_query; ?&gt;

	&lt;h2 id="comments"&gt;&lt;?php comments_number('No Responses', 'One Response', '% Responses' ); ?&gt;&lt;h2&gt;

	&lt;?php if (!empty($comments_by_type['comment'])) { ?&gt;

		&lt;h3 id="comments"&gt;&lt;?php echo count($wp_query-&gt;comments_by_type['comment']); ?&gt; Comments&lt;h3&gt;
		&lt;ol class="commentlist"&gt;
			&lt;?php wp_list_comments('type=comment'); ?&gt;
		&lt;/ol&gt;

	&lt;?php } ?&gt;
	&lt;?php if (!empty($comments_by_type['pingback'])) { ?&gt;

		&lt;h3 id="pingbacks"&gt;&lt;?php echo count($wp_query-&gt;comments_by_type['pingback']); ?&gt; Pingbacks&lt;/h3&gt;
		&lt;ol class="pingbacklist"&gt;
			&lt;?php wp_list_comments('type=pingback'); ?&gt;
		&lt;/ol&gt;

	&lt;?php } ?&gt;
	&lt;?php if (!empty($comments_by_type['trackback'])) { ?&gt;

		&lt;h3 id="trackbacks"&gt;&lt;?php echo count($wp_query-&gt;comments_by_type['trackback']); ?&gt; Trackbacks&lt;/h3&gt;
		&lt;ol class="trackbacklist"&gt;
			&lt;?php wp_list_comments('type=trackback'); ?&gt;
		&lt;/ol&gt;

	&lt;?php } ?&gt;

&lt;?php else : // if there are no comments yet ?&gt;

	&lt;?php if (comments_open()) : ?&gt;
		&lt;!-- comments open, no comments --&gt;
	 &lt;?php else : ?&gt;
		&lt;!-- comments closed, no comments --&gt;
	&lt;?php endif; ?&gt;

&lt;?php endif; ?&gt;</code></pre>
<p>That&rsquo;s the magic bullet right there. Used as your comments loop, this code will display separate comments, pingbacks, and trackbacks, with each showing their respective number of responses in its heading. Notice we threw in some additional code there to make everything completely plug-n-play. Bottom line: slap it in and test it yourself. Should work perfectly for all WordPress 2.7 and better.</p>
<h3>Separate comments from both pingbacks and trackbacks</h3>
<p>Note that, alternately, you could segregate comments from both pingbacks <em>and</em> trackbacks, such that your comments display would show something like this:</p>
<p><img src="http://digwp.com/wp-content/blog-images/comments-trackbacks.gif" alt="[ Separated display of comments from both pingbacks and trackbacks ]" /></p>
<p>To do this, we modify the comment loop (from Step 1 above) like so:</p>
<pre><code>&lt;?php if (!empty($comments_by_type['comment'])) { ?&gt;

	&lt;h3 id="comments"&gt;Comments&lt;h3&gt;
	&lt;ol class="commentlist"&gt;
		&lt;?php wp_list_comments('type=comment'); ?&gt;
	&lt;/ol&gt;

&lt;?php } if (!empty($comments_by_type['pings'])) { ?&gt;

	&lt;h3 id="trackbacks"&gt;Pingbacks &amp;amp; Trackbacks&lt;/h3&gt;
	&lt;ol class="ping-trackbacklist"&gt;
		&lt;?php wp_list_comments('type=pings'); ?&gt;
	&lt;/ol&gt;

&lt;?php } ?&gt;</code></pre>
<p>Grouping the pingbacks and trackbacks is easy thanks to the &ldquo;<code>pings</code>&rdquo; parameter for the second <code>wp_list_comments</code> loop. Then to display the count for our combined pingbacks and trackbacks, we insert the following snippet into our &ldquo;Pingbacks &amp; Trackbacks&rdquo; heading (similar to Step 2 above):</p>
<pre><code>&lt;?php echo count($wp_query-&gt;comments_by_type['pings']); ?&gt;</code></pre>
<p>That&rsquo;s all there is to it! Once you get everything in place and working properly, you&rsquo;ll have some clean <acronym title="Hypertext Markup Language">HTML</acronym> canvas to paint with any <acronym title="Cascading Style Sheets">CSS</acronym> styles you wish. Sounds like a great way to spend some time&nbsp;;)</p>
<p style="border:1px solid #ccc; background: #eee; line-height: 20px; padding: 5px 10px; margin-top: 10px;">Like the article? <a href="http://digwp.com/book"><strong>Get the book!</strong></a></p>
<hr />
<p><small>© 2010 <a href="http://digwp.com">Digging into WordPress</a> | <a href="http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/">Permalink</a> | <a href="http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/#comments">15 comments</a> | Add to
<a href="http://del.icio.us/post?url=http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/&title=Display Separate Counts for Comments, Pingbacks and&nbsp;Trackbacks">Delicious</a><br />
Categorized: <a href="http://digwp.com/category/design/" title="View all posts in Design" rel="category tag">Design</a>, <a href="http://digwp.com/category/php/" title="View all posts in PHP" rel="category tag">PHP</a> | Tagged: <a href="http://digwp.com/tag/comments/" rel="tag">comments</a>, <a href="http://digwp.com/tag/tips/" rel="tag">tips</a>, <a href="http://digwp.com/tag/tricks/" rel="tag">tricks</a></small></p>]]></content:encoded>
			<wfw:commentRss>http://digwp.com/2010/02/separate-comments-pingbacks-trackbacks/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
	</channel>
</rss>
