<?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>WordPress Hacks &#187; Hacks</title>
	<atom:link href="http://wphacks.com/category/hacks/feed/" rel="self" type="application/rss+xml" />
	<link>http://wphacks.com</link>
	<description>WordPress Themes, Plugins, Hacks, Tutorials, and more!</description>
	<lastBuildDate>Sat, 19 May 2012 22:29:47 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>CRON Jobs Give WordPress Users Peace of Mind</title>
		<link>http://wphacks.com/wordpress-cron-jobs/</link>
		<comments>http://wphacks.com/wordpress-cron-jobs/#comments</comments>
		<pubDate>Mon, 02 May 2011 15:35:37 +0000</pubDate>
		<dc:creator>Jennifer Nodwell</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[CRON]]></category>
		<category><![CDATA[WordPress Database Backup]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=3138</guid>
		<description><![CDATA[This guest post was written by Jennifer Nodwell, a coder and website developer since 1997 who works almost exclusively with open source CMS applications like WordPress. If you have webmaster or WordPress knowledge and are interested in writing a post for WordPress Hacks, please contact us. If you&#8217;ve never had a website go missing, then you&#8217;re very [...]]]></description>
			<content:encoded><![CDATA[<p><em>This guest post was written by Jennifer Nodwell, a coder and website developer since 1997 who works almost exclusively with open source CMS applications like WordPress. If you have webmaster or WordPress knowledge and are interested in <a href="http://wphacks.com/write/">writing a post for WordPress Hacks</a>, please <a href="http://wphacks.com/contact/">contact us</a>.</em></p>
<p>If you&#8217;ve never had a website go missing, then you&#8217;re very lucky. Your host can have a network error or hardware failure that loses your site&#8217;s files. A malicious hacker can penetrate your FTP server and replace your site with files of his choice. You might get curious about a new plugin, install it, and break your site to pieces in the process. No words really describe the panic you feel when you realize your website is gone!</p>
<p>If your host allows you to use CRON jobs, you can protect yourself from all those things by running a daily backup of your database and web site files. If you lose your site for any reason, you can put it right back in a few minutes.</p>
<p>A CRON job is script that your web server executes at a specified time. CRON comes from the word chronograph, and it is a time-based job scheduler for LINUX based operating systems. Most WordPress sites are running on such an operating system. If you have access to a CRON scheduler through your hosting control panel or have command-line access to your hosting server, you should be able to write a shell script to back up your database and site files.</p>
<p>The first thing you will need is a shell script. The script will connect to your database, export the whole thing to a file, and zip the file up so you can store it safely somewhere. Then, it will zip up all your website files.</p>
<p>If you have a host panel where you can create and edit a file, you can do this there. Otherwise, open any non WYSIWYG text editor and create a file called daily_backups.sh. The .sh file extension indicates this is a shell script file.</p>
<p><code>#!/bin/sh<br />
TERM=linux<br />
export TERM<br />
NOWDATE=`date +%a` # Sets the date variable format for zipped file: Sun<br />
clear # clears terminal window<br />
echo<br />
echo "Hi, $USER!"<br />
echo<br />
mysqldump --opt -Q -h your-website-host-name --user=your-db-user-name --password=your-db-password your-database-name | gzip -v9 - &gt; /www/public_html/backups/MySQL-$NOWDATE-yourwebsite.sql.gz</code></p>
<p>The first line is an indicator to the server for which shell processing language to use. Your server might require</p>
<p><code>#!/bin/bash</code> or something else there. Use <code>echo $SHELL</code> from the command prompt to determine your shell type if you have command line access.</p>
<p>The <code>TERM</code> instruction tells the server what terminal type it is communicating with; in this case, a text terminal.</p>
<p>Next we create a variable named <code>NOWDATE</code> and use a little script magic to set it to be equal to the abbreviation for the current day of the week e.g. Sun, Mon, Tue, etc.</p>
<p>The <code>mysqldump</code> command will &#8220;dump&#8221; the entire database including create procedures and insert procedures for all the current data.</p>
<p>Replace <code>your-website-host-name</code> with your website host name for your database. You can find this in your wp-config file if you don&#8217;t know it.</p>
<p>Replace <code>your-db-user-name</code>, <code>your-db-password</code>, <code>your-db-name</code> with actual values. Again, these values are likely exactly what they are in your wp-config file.</p>
<p>Replace <code>/www/public_html/</code> with whatever your hosting account&#8217;s root path is.</p>
<p>Replace <code>yourwebsite</code> with some meaningful name.</p>
<p>Now, save the file. You need to set the permissions on the file so that it is executable. If your cpanel has a cron scheduler, just add this file to the list of files it runs. If you need to edit your crontab from command line, see this <a title="Linux Crontab" href="http://cjeweb.com/blog/164/linux-crontab/" target="_blank">tutorial</a>.</p>
<p>To back up your site files, as well as your database, add a few more lines to your script.</p>
<p><code>echo<br />
echo "Zipping wordpress directory structure..."<br />
tar -czf $HOME/backups/$NOWDATE.mywebsite.tar.gz $HOME/public_html/*</code></p>
<p>Hopefully, you do have a directory outside your public web root so that your backup files are stored in a location that is not accessible via the internet.</p>
<p>The tar command will pack the files up into a tarball for you (like a zip archive).</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=3138&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/wordpress-cron-jobs/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How To: Add Google Rich Snippets to WordPress (Without Editing Your Theme)</title>
		<link>http://wphacks.com/how-to-add-google-rich-snippets-to-wordpress-without-editing-your-theme/</link>
		<comments>http://wphacks.com/how-to-add-google-rich-snippets-to-wordpress-without-editing-your-theme/#comments</comments>
		<pubDate>Thu, 24 Jun 2010 20:33:44 +0000</pubDate>
		<dc:creator>John Lamansky</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[SEO]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[hReview]]></category>
		<category><![CDATA[microformats]]></category>
		<category><![CDATA[rich snippets]]></category>
		<category><![CDATA[SEO Ultimate]]></category>
		<category><![CDATA[WordPress How-To]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2706</guid>
		<description><![CDATA[This guest post was written by John of WordPress Expert, where he provides WordPress tips, tutorials, news, plugins, and more. If you have WordPress knowledge and are interested in writing a post for WordPress Hacks, please contact us. When searching the web with Google, have you ever noticed that certain webpages with product reviews have [...]]]></description>
			<content:encoded><![CDATA[<p><em>This guest post was written by John of <a href="http://wordpress.jdwebdev.com/">WordPress Expert</a>, where he provides WordPress tips, tutorials, news, plugins, and more. If you have WordPress knowledge and are interested in <a href="/write/">writing a post for WordPress Hacks</a>, please <a href="/contact/">contact us</a>.</em></p>
<p>When searching the web with Google, have you ever noticed that certain webpages with product reviews have a little star-rating and additional info that appears underneath the title?</p>
<p>For example&#8230;</p>
<p><img src="http://wordpress.jdwebdev.com/images/wphacks/seo-ultimate-rich-snippet-example.jpg" alt="Rich snippet example" /></p>
<p>Notice the additions under the hyperlinked title. These eye-catching additions are called <strong>&#8220;rich snippets.&#8221;</strong> Rich snippets give additional prominence to your review pages when they appear in search results and could help garner additional search engine traffic for your site.</p>
<p>You can ask Google to show this sort of data for your review posts by adding hReview code to your WordPress blog. This process has been covered in other tutorials before, but previous methods required you to edit your theme&#8217;s code and fiddle with custom fields to get it to work. Not anymore &#8212; <strong>here&#8217;s the easier, plugin-only method:</strong></p>
<ol>
<li>Install the <a href="http://wordpress.org/extend/plugins/seo-ultimate/">SEO Ultimate</a> plugin. (You can <a href="http://downloads.wordpress.org/plugin/seo-ultimate.zip">download the zip file here</a> or you can go to the <a href="http://www.seodesignsolutions.com/wordpress-seo/">SEO Ultimate homepage</a> and enter your blog&#8217;s URL in the Auto Installer field.) Activate the plugin once it&#8217;s installed. SEO Ultimate has many other SEO features besides rich snippets, but if you just want to use the rich snippet functionality, you can disable everything else under the &#8220;Modules&#8221; section of the plugin&#8217;s &#8220;SEO&#8221; menu.</li>
<li>In the WordPress administration interface, find a post that you&#8217;d like to mark as a review and open it in the WordPress editor.</li>
<li>In the &#8220;SEO Settings&#8221; box under the content editor, select &#8220;Review&#8221; from the &#8220;Rich Snippet Type&#8221; drop-down. (If your post has a category or tag called &#8220;Review&#8221; or &#8220;Reviews,&#8221; SEO Ultimate will pre-select the &#8220;Review&#8221; option automatically.)</li>
<li>If you gave a rating to the product you reviewed in your post, select the most-applicable star rating from the drop-down.</li>
<li>Click &#8220;Save Changes&#8221; to save your post. All done! If you want, you can put your post URL through <a href="http://www.google.com/webmasters/tools/richsnippets">Google&#8217;s testing tool</a> to see a preview of your new rich snippets.</li>
</ol>
<p><img src="http://wordpress.jdwebdev.com/images/wphacks/seo-ultimate-seo-settings.jpg" alt="SEO Settings box" /></p>
<p>Following these steps will tell SEO Ultimate to add the hReview code to your reviews. (Obviously, only add the code to posts in which you actually review something.)</p>
<p>Note that <a href="http://knol.google.com/k/google-rich-snippets-tips-and-tricks#How_do_I_get_Rich_Snippets_to_show_up_for_my_site%283F%29">according to Google&#8217;s FAQ</a>, adding the code by itself won&#8217;t guarantee that Google will show rich snippets for your site. However, you can request that Google display rich snippets for your site using <a href="http://www.google.com/support/webmasters/bin/request.py?contact_type=rich_snippets_feedback">this form</a>. Even if Google doesn&#8217;t show your rich snippets right away, having the code on your site ahead of time will help ensure you&#8217;re ahead of the game if/when Google rolls out rich snippets on a wider scale.</p>
<p>Enjoy your rich snippets!</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2706&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/how-to-add-google-rich-snippets-to-wordpress-without-editing-your-theme/feed/</wfw:commentRss>
		<slash:comments>30</slash:comments>
		</item>
		<item>
		<title>How To: Add a Twitter Link to Your WordPress Blog</title>
		<link>http://wphacks.com/add-twitter-link-to-wordpress-blog/</link>
		<comments>http://wphacks.com/add-twitter-link-to-wordpress-blog/#comments</comments>
		<pubDate>Wed, 05 May 2010 01:16:44 +0000</pubDate>
		<dc:creator>Kyle Eslick</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[Twitter Code]]></category>
		<category><![CDATA[Twitter WordPress]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>
		<category><![CDATA[WordPress Tips]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2591</guid>
		<description><![CDATA[Twitter is all the rage these days and it doesn&#8217;t seem like it will be going anywhere any time soon.  With that said, it often surprises me that many WordPress blog owners  don&#8217;t offer a convenient way for their readers to retweet their content.  Anyone can grab a Twitter WordPress plugin to tweet their new content as [...]]]></description>
			<content:encoded><![CDATA[<p>Twitter is all the rage these days and it doesn&#8217;t seem like it will be going anywhere any time soon.  With that said, it often surprises me that many WordPress blog owners  don&#8217;t offer a convenient way for their readers to retweet their content.  Anyone can grab a Twitter WordPress plugin to tweet their new content as it is published, but what about your older content?</p>
<p>Rather than passing up all that potential traffic, I&#8217;ve found that offering a link somewhere within your post (optimally at the bottom of each post) is a great way to help your readers and incoming search engine traffic to promote your content for you.  When people find great content they like to share it with others, so why not make it easy for them?</p>
<p>Not only is adding a &#8220;Tweet This!&#8221; link a great choice, but it is really easy to do.  Chances are if you do a search on Google for code to use you&#8217;ll find something <a href="http://wphacks.com/how-to-adding-a-twitter-link-wordpress-theme/">like the following</a>:</p>
<p><code>&lt;a href="http://twitter.com/home?status=Currently reading &lt;?php the_permalink(); ?&gt;" title="Click to send this page to Twitter!" target="_blank"&gt;Tweet This!&lt;/a&gt;</code></p>
<p>This code works just fine, but is not the most optimal solution in my opinion.  Depending on the permalink structure your WordPress blog uses, combined with the length of your domain name, it may be difficult to fit the link into a 140 character tweet.  It also doesn&#8217;t leave room for the person to add their own comments to the tweet.</p>
<p>As a proposed solution, I recommend using some WordPress code like the following:</p>
<p><code>&lt;a href="http://twitter.com/home?status=RT @HackWordPress &lt;?php the_title ();?&gt; &lt;?php echo get_settings('home'); ?&gt;/?p=&lt;?php the_ID(); ?&gt;"&gt;Tweet This&lt;/a&gt;</code></p>
<p>This code will automatically insert the &#8220;RT&#8221; and your Twitter account name (the above example uses our Twitter account, <a href="http://twitter.com/HackWordpress">@HackWordPress</a>) then use the ID form of your post with the tweet.  When people click the link in the tweet, they will then be redirected to the actual post using your blog&#8217;s selected permalink structure, making a convenient and typically short URL.</p>
<p>Have you integrated Twitter into your WordPress blog? Share your strategies in the comments!</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2591&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/add-twitter-link-to-wordpress-blog/feed/</wfw:commentRss>
		<slash:comments>15</slash:comments>
		</item>
		<item>
		<title>Page Sensitive Multi-Level Navigation</title>
		<link>http://wphacks.com/page-sensitive-multi-level-navigation/</link>
		<comments>http://wphacks.com/page-sensitive-multi-level-navigation/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 15:56:01 +0000</pubDate>
		<dc:creator>V Scott Ellis</dc:creator>
				<category><![CDATA[How-To]]></category>
		<category><![CDATA[navigation]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Navigation]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2409</guid>
		<description><![CDATA[While most sites don&#8217;t need incredibly deep page navigation there are situations that justify a hierarchy beyond the typical 2 &#8211; 3 levels.  Unfortunately that can be cumbersome for top navigation drop-downs (more than 1 level of drop down is too much IMHO) so another solution needs to be found.  I ran into just such [...]]]></description>
			<content:encoded><![CDATA[<p>While most sites don&#8217;t need incredibly deep page navigation there are situations that justify a hierarchy beyond the typical 2 &#8211; 3 levels.  Unfortunately that can be cumbersome for top navigation drop-downs (more than 1 level of drop down is too much IMHO) so another solution needs to be found.  I ran into just such a situation for a client and while I&#8221;m also not a fan of left hand navigation it was the decision of the client to utilize it in conjunction with their top navigation, and in retrospect it made sense for them. To keep things easily navigable we also implemented breadcrumbs (which is a good practice anyway).</p>
<p>The mission was to display sub-pages of the current page you are on in the left nav and once you hit the bottom of the hierarchy to show pages which are parallel to that page within the same branch of the hierarchy.</p>
<p>After some digging and experimentation I came up with the following which executes perfectly in only a few lines of code.</p>
<p><code>&lt;?php<br />
$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;ID."&amp;echo=0&amp;depth=1");<br />
if ($children == "")<br />
$children = wp_list_pages("title_li=&amp;child_of=".$post-&gt;post_parent."&amp;echo=0&amp;depth=1");<br />
?&gt;<br />
&lt;ul&gt;<br />
&lt;?php echo $children; ?&gt;<br />
&lt;/ul&gt;<br />
&lt;?php endif; ?&gt;</code></p>
<p>Of course you style to taste&#8230;</p>
<p>That&#8217;s it! Used in conjunction with a standard WordPress top-navigation and breadcrumbs you can easily display page sensitive multi-level navigation for your super-complex multi-level site!</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2409&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/page-sensitive-multi-level-navigation/feed/</wfw:commentRss>
		<slash:comments>31</slash:comments>
		</item>
		<item>
		<title>Security Reminder: Upgrading Your WordPress Blogs</title>
		<link>http://wphacks.com/security-reminder-upgrading-your-wordpress-blogs/</link>
		<comments>http://wphacks.com/security-reminder-upgrading-your-wordpress-blogs/#comments</comments>
		<pubDate>Mon, 07 Sep 2009 20:40:21 +0000</pubDate>
		<dc:creator>Kyle Eslick</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Upgrade WordPress]]></category>
		<category><![CDATA[WordPress Blogs]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Security]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2339</guid>
		<description><![CDATA[While I was away over the weekend, it appears that a large number of bloggers who use WordPress have been hacked and a lot of damage has been done.  It seems this problem has shown up for a large number of people, including some very high profile bloggers.  Among them was Robert Scoble, whose blog [...]]]></description>
			<content:encoded><![CDATA[<p>While I was away over the weekend, it appears that a large number of bloggers who use WordPress have been hacked and a lot of damage has been done.  It seems this problem has shown up for a large number of people, including some very high profile bloggers.  Among them was <a href="http://scobleizer.com/2009/09/05/i-dont-feel-safe-with-wordpress-hackers-broke-in-and-took-things/">Robert Scoble</a>, whose blog was among those websites which were hacked.   Damages on Scoble&#8217;s site included porn information being placed in old posts, 2 entire months of content being deleted, and more.  Of course the porn then led to his blog being completely banned from Google!   Scoble is not the only one having these problems, however, and even lesser known bloggers have been attacked.  You can read more in this <a href="http://wordpress.org/support/topic/307518">WordPress support forum thread</a>.</p>
<p>If you are wondering what the one thing all of these WordPress sites have in common, the problem is they were all using old versions of WordPress.   As someone that owns and operates well over 100 WordPress installations, I certainly understand the pain it can be to upgrade to the latest version of WordPress every time a new release happens, but I hope this goes to show why it is so important to take the time to upgrade all of your WordPress installations be using the most recent version of WordPress.</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2339&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/security-reminder-upgrading-your-wordpress-blogs/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Separating Trackbacks from Comments in WordPress 2.7+</title>
		<link>http://wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/</link>
		<comments>http://wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/#comments</comments>
		<pubDate>Sun, 16 Aug 2009 15:39:11 +0000</pubDate>
		<dc:creator>Kyle Eslick</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Seperating Trackbacks from Comments]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[WordPress 2.7]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2287</guid>
		<description><![CDATA[Back when WordPress 2.7 was released, the WordPress team introduced a completely revamped comment form that included integration of threaded comments into the core software, introducing some dramatic changes with how comments are handled.   Unfortunately, this change broke one of the most popular comment hacks, separating trackbacks from comments. Since then, several people have stepped [...]]]></description>
			<content:encoded><![CDATA[<p>Back when <a href="http://wphacks.com/wordpress-27-now-available-for-download/">WordPress 2.7 was released</a>, the WordPress team introduced a completely revamped comment form that included integration of threaded comments into the core software, introducing some dramatic changes with how comments are handled.   Unfortunately, this change broke one of the most popular comment hacks, <a href="http://wphacks.com/how-to-separate-wordpress-comments-and-trackbacks/">separating trackbacks from comments</a>.</p>
<p>Since then, several people have stepped up and shared some great hacks for separating trackbacks from comment in WordPress 2.7 or newer blogs .  So far the best guide I&#8217;ve found came from Sivel.net, which can be viewed <a href="http://sivel.net/2008/10/wp-27-comment-separation/">here</a>.  Click over and follow those steps get everything separated.</p>
<p><em>Note: The above guide is only for people using WordPress 2.7 or newer installations.  For people using WordPress 2.6 or earlier, you&#8217;ll want to use <a href="http://wphacks.com/how-to-separate-wordpress-comments-and-trackbacks/">this tutorial</a>.</em></p>
<p>Once you&#8217;ve got the comments successfully separated from the trackbacks, there are a couple additional tweaks you may want to do to clean up how things look (it really depends on preference I suppose).   The first is to clean up your trackbacks/pingbacks by only displaying the title instead of an excerpt and everything else.   In order to do this, you&#8217;ll need to find the following code in your comments.php file:</p>
<p><code>&lt;ol&gt;<br />
&lt;?php wp_list_comments('type=pings'); ?&gt;<br />
</code></p>
<p>Now <strong>replace</strong> that code with the following:</p>
<p><code>&lt;ol&gt;<br />
&lt;?php wp_list_comments('type=pings&amp;callback=list_pings'); ?&gt;<br />
</code></p>
<p>Lastly, you&#8217;ll need to add the following code to your functions.php file (which can be created if you don&#8217;t already have one):</p>
<p><code>&lt;?php<br />
function list_pings($comment, $args, $depth) {<br />
$GLOBALS['comment'] = $comment;<br />
?&gt;<br />
&lt;li id="comment-&lt;?php comment_ID(); ?&gt;"&gt;&lt;?php comment_author_link(); ?&gt;<br />
&lt;?php } ?&gt;<br />
</code></p>
<p>That should clean up the trackbacks/pingbacks section and you can also apply the same changes if you use a plugin to display tweetbacks.</p>
<p>The other thing you may want to do is fix the comment count to only show actual comments, filtering out the trackbacks/pingbacks which are included in your comment count by default.   Simply add the following code to your functions.php file (which again can be created if you don&#8217;t already have one):</p>
<p><code>&lt;?php<br />
add_filter('get_comments_number', 'comment_count', 0);<br />
function comment_count( $count ) {<br />
if ( ! is_admin() ) {<br />
global $id;<br />
$comments_by_type = &amp;separate_comments(get_comments('status=approve&amp;post_id=' . $id));<br />
return count($comments_by_type['comment']);<br />
} else {<br />
return $count;<br />
}<br />
}<br />
?&gt;<br />
</code></p>
<p>So there you go.  Anyone have any other tips for cleaning up your comment form?</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2287&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/separating-trackbacks-from-comments-in-wordpress-2-7/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How to: Use Thumbnails Generated by WordPress</title>
		<link>http://wphacks.com/how-to-use-thumbnails-generated-by-wordpress/</link>
		<comments>http://wphacks.com/how-to-use-thumbnails-generated-by-wordpress/#comments</comments>
		<pubDate>Wed, 22 Jul 2009 15:25:11 +0000</pubDate>
		<dc:creator>Alex Denning</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[Media]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress Tips]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2183</guid>
		<description><![CDATA[One of ten brilliant tips that I shared yesterday on my blog &#8211; display images on your blog&#8217;s homepage without any custom fields or any additional functions.php script, something I first saw on  WebDeveloperPlus. How do you do it? First log in, on the sidebar select &#8216;Media&#8217; (which is under &#8216;Settings&#8217;). You&#8217;ll then be taken [...]]]></description>
			<content:encoded><![CDATA[<p>One of ten brilliant tips that <a href="http://wpshout.com/10-tips-to-improve-your-wordpress-theme/">I shared yesterday on my blog</a> &#8211; display images on your blog&#8217;s homepage without any custom fields or any additional functions.php script, something I first saw on  <a href="http://webdeveloperplus.com/wordpress/how-to-use-thumbnails-generated-by-wordpress-in-your-theme/">WebDeveloperPlus</a>.</p>
<p>How do you do it? First log in, on the sidebar select &#8216;Media&#8217; (which is under &#8216;Settings&#8217;). You&#8217;ll then be taken to a page with an option to change the thumbnail size of images. Change that to whatever size you want your images to appear as. Next, insert the code below onto your homepage, archive page, whatever.</p>
<p><code>&lt;?php<br />
//Get images attached to the post<br />
$args = array(<br />
'post_type' =&gt; 'attachment',<br />
'post_mime_type' =&gt; 'image',<br />
'numberposts' =&gt; -1,<br />
'order' =&gt; 'ASC',<br />
'post_status' =&gt; null,<br />
'post_parent' =&gt; $post-&gt;ID<br />
);<br />
$attachments = get_posts($args);<br />
if ($attachments) {<br />
foreach ($attachments as $attachment) {<br />
$img = wp_get_attachment_thumb_url( $attachment-&gt;ID );<br />
break; }<br />
//Display image<br />
} ?&gt;<br />
</code></p>
<p>Then, to display your image you can just echo out the $img tag we just created:</p>
<p><code>&lt;img src="&lt;?php echo $img; ?&gt;" alt=" " /&gt;<br />
</code><br />
And there we have it. I told you it was easy! This is one of the tips from a post I wrote yesterday on WPShout &#8211; &#8216;<a href="http://wpshout.com/10-tips-to-improve-your-wordpress-theme/">10 Tips to Improve Your WordPress Theme</a>&#8216;.</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2183&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/how-to-use-thumbnails-generated-by-wordpress/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>How To: Hack WordPress Theme Template Pages</title>
		<link>http://wphacks.com/how-to-hack-wordpress-theme-template-pages/</link>
		<comments>http://wphacks.com/how-to-hack-wordpress-theme-template-pages/#comments</comments>
		<pubDate>Mon, 18 May 2009 09:00:02 +0000</pubDate>
		<dc:creator>JTPratt Media</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Theme Templates]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>
		<category><![CDATA[WordPress Tips]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2029</guid>
		<description><![CDATA[The key to being able to display exactly what you want in WordPress is understanding WordPress theme template pages. These are the theme files that display pages, not the ones that perform functions like comments, sidebar, etc. Most of us don&#8217;t use the WordPress default theme that comes with installation, and end up downloading a [...]]]></description>
			<content:encoded><![CDATA[<p>The key to being able to display exactly what you want in WordPress is understanding WordPress theme template pages. These are the theme files that display pages, not the ones that perform functions like comments, sidebar, etc. Most of us don&#8217;t use the WordPress default theme that comes with installation, and end up downloading a free theme from the Internet. This is a great way to customize your blog, but not all theme authors code their theme the same way. The capabilities of that theme largely depend on how much time the web designer took to code it, in addition to their knowledge of WordPress itself.</p>
<p>I&#8217;m going to explain everything you need to know to be able to customize all your theme pages any way you want, and this will give you enough information to begin coding your own theme as well. Even if you&#8217;re an &#8216;expert&#8217; theme coder, you should learn something new from this article.</p>
<h3>How WordPress Works</h3>
<p>The most important thing you could learn about WordPress is the <a href="http://codex.wordpress.org/Template_Hierarchy">Template Hierarchy</a>, or &#8211; &#8220;the order in which WordPress calls pages&#8221;. The ONLY file that is required in the PHP files of any WordPress theme is the &#8220;index.php&#8221;. That&#8217;s it! That one file <em>could</em> handle every single function WordPress performs (if you wanted it to). Or, you could have a WordPress theme that had a PHP theme for for every single WP function (or anything in between).</p>
<h4>The Order of Things</h4>
<p>Every time a WordPress page is called the WP &#8216;engine&#8217;, if you will, determines (through process of elimination) what kind of page it is. It&#8217;s kind of like a &#8220;where am I?&#8221; function. WordPress says &#8220;what page am I&#8230;&#8221; and in turn tries to call pages in a specific order. If WP doesn&#8217;t find the PHP file it needs it just defaults to the &#8220;index.php&#8221; file and uses it instead. There are 9 basic kinds of pages WordPress looks for first:</p>
<p><strong>Am I the Home Page?</strong><br />
If WP thinks it&#8217;s on the home page it will look for &#8220;home.php&#8221; first, and &#8220;index.php&#8221; second.</p>
<p><strong>Am I Post Page?</strong><br />
(Single) post pages look for &#8220;single.php&#8221; first, and then default to &#8220;index.php&#8221;.</p>
<p><strong>Am I a &#8216;Paged&#8217; Page?</strong><br />
(Static) or &#8216;paged&#8217; pages in WordPress look for a &#8220;pagetemplate.php&#8221; first (if assigned when published), &#8220;page.php&#8221; second, and default to &#8220;index.php&#8221; last.</p>
<p><strong>Am I a Category Page?</strong><br />
When WordPress determines it&#8217;s on a category page first it looks like a category specific ID page, such as &#8220;category-7.php&#8221;. If it doesn&#8217;t find that it next looks for a &#8220;category.php&#8221; (which would be used on every category page). If that&#8217;s not there is searches for &#8220;archive.php&#8221;, and last it defaults to &#8220;index.php&#8221;.</p>
<p><strong>Am I a Tag Page?</strong><br />
If WordPress is on a tag page it tries to load &#8220;tag-slug.php&#8221; first, with &#8216;slug&#8217; being the name of your tag. If your tag is &#8216;wordpress hacks&#8217; the tag slug page would be &#8220;tag-wordpress-hacks.php&#8221;. It that&#8217;s not available, WP next looks for &#8220;tag.php&#8221; which would load for all tag pages, then &#8220;archive.php&#8221;, and if that&#8217;s not there last it defaults to &#8220;index.php&#8221;.</p>
<p><strong>Am I an Author Page?</strong><br />
If your blog has multiple authors, first it looks for &#8220;author.php&#8221; to display the details. If that&#8217;s not there, it tries to load &#8220;archive.php&#8221;, and last it defaults to &#8220;index.php&#8221;.</p>
<p><strong>Am I an Archive Page?</strong><br />
Archive pages are loaded when WordPress loads a date based page for previous posts. First it tries to load &#8220;date.php&#8221;, then &#8220;archive.php&#8221;, and last it defaults to &#8220;index.php&#8221;.</p>
<p><strong>Am I a Search or 404 Page?</strong><br />
If WP determines it&#8217;s on a search (results) or 404 (not found) page the it tries to load either search.php or 404.php. If not, the default is once again &#8220;index.php&#8221;.</p>
<p><strong>Am I an Attachment?</strong><br />
Out of all the WordPress theme template pages, the attachment page is probably the one used least, and I have to admit &#8211; I&#8217;ve not seen a single one of these in any of the hundreds of themes I&#8217;ve downloaded. WordPress uses these special pages usually for uploaded content, which would explain why it first looks for &#8220;image.php&#8221;, &#8220;audio.php&#8221;, &#8220;video.php&#8221;, or &#8220;application.php&#8221;. Then it tries to find &#8220;attachment.php&#8221; or &#8220;single.php&#8221;, and if none of those are available it also defaults to &#8220;index.php&#8221;.</p>
<h3>Inner Workings of WP Theme Templates</h3>
<p>As I said before, you <em>could</em> use a single index.php file to handle the 9 types of pages. You would simply code in some <a href="http://wphacks.com/wordpress-conditional-tags-hack-theme/">conditional tags</a>, like I showed you in the last tutorial I wrote here on WP Hacks. A single index.php would then just contain code to say if is_home, do this, if is_single do that, etc. That&#8217;s a lot of code for just one page, and a bit unorganized &#8211; and it doesn&#8217;t leave a lot of room for customization.</p>
<p>Coincidentally, like WordPress searches for 9 basic pages &#8211; each theme template page also contains 9 basic WordPress elements:</p>
<ol>
<li>a header call</li>
<li>opening of &#8216;the loop&#8217;</li>
<li>a call to get the permalink and (some) meta</li>
<li>a call telling WordPress what to get</li>
<li>a call to get either the content or an excerpt</li>
<li>(maybe) more meta</li>
<li>closing of &#8216;the loop&#8217;</li>
<li>a sidebar call</li>
<li>a footer call</li>
</ol>
<p>Those are only the WordPress elements, of course the PHP code to make them work is usually scattered throughout the appropriate HTML code make your theme&#8217;s layout and graphic design work properly. I&#8217;m going to explain these elements a bit more so you can understand how you can customize (or create) nearly any theme template page.</p>
<p><strong>Header, Sidebar, and Footer calls</strong></p>
<p>I&#8217;m going to handle all 3 of these elements at once, since they are all basically the same. When you see this code in a template:</p>
<p><code>&lt;?php get_header(); ?&gt;</code></p>
<p>WordPress is simply opening the &#8220;header.php&#8221; file. The same is true for get_sidebar (sidebar.php) and get_footer (footer.php). You could have multiple headers, footers, or sidebars, see the earlier link above for conditional tags.</p>
<p><strong>Opening of &#8220;the loop&#8221;</strong></p>
<p>The infamous &#8220;<a href="http://codex.wordpress.org/The_Loop">WordPress Loop</a>&#8221; is when a call goes out to the database to do something until WordPress says &#8220;stop&#8221;, i.e. &#8216;get me the most recent full text posts in their entirety&#8217;. The structure of &#8216;the loop&#8217; changes depending on what kind of page your displaying, and each of the 9 basic types of pages WordPress tries to load has a &#8216;loop&#8217;.</p>
<p>The opening of the loop generally looks like this:</p>
<p><code>&lt;?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?&gt;</code></p>
<p>You may see it broken down with have_posts on one line to define conditional tags with the while and the_post on another, but it&#8217;s still the opening of the loop, and it&#8217;s pretty much the same in all pages. One way to use the multi-line loop opending is to place a parameter between &#8220;if have_posts&#8221; and the rest by using <a href="http://codex.wordpress.org/Template_Tags/query_posts">query_posts</a> in between to show only a single post, posts from a time period, the last post only, posts from certain categories, or even change the ordering of posts being iterated in the loop.</p>
<p><strong>A Call to Get the Permalink and (some) meta</strong><br />
The very last section of the loop opening (the_post) actually makes individual data available through each iteration of the loop. This data referred to usually as &#8220;<a href="http://codex.wordpress.org/Post_Meta_Data_Section">post meta</a>&#8221; because it&#8217;s descriptors and identifiers for the individual content being looped through. Typically things like the permalink (URL), title, date, etc. I say &#8216;some&#8217; meta, because most themes show some things before the individual post content, and then some after &#8211; such as categories and tags.</p>
<p>Here&#8217;s a short list of things you can call in post meta: the_permalink, the_ID, the_title, the_time, the_author, the_author_email, the_author_posts_link, the_category, single_cat_title, the_tags, single_tag_titls, edit_post_link, comments_popup_link, comments_rss_link</p>
<p>Example code you might see for post meta would be something like this:</p>
<p><code>&lt;div class="post" id="post-&lt;?php the_ID(); ?&gt;"&gt;<br />
&lt;h2&gt;&lt;a href="&lt;?php the_permalink() ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;<br />
&lt;/div&gt;</code></p>
<p><strong>A Call Telling WP What to Get</strong><br />
Next WordPress will decide how much of the actual individual post content to get for you. How much is gathered from the database depends on whether your look uses &#8220;<a href="http://codex.wordpress.org/Template_Tags/the_content">the_content</a>&#8221; (to get it all) or &#8220;<a href="http://codex.wordpress.org/Template_Tags/the_excerpt">the_excerpt</a>&#8221; (to get part of it).</p>
<p><strong>(Maybe) more meta</strong><br />
As I previously mentioned, the common things to see after a post are assigned categories or tags, and sometimes you see an &#8220;edit&#8221; link here as well. Some themes even put date published meta after the post content.</p>
<p><strong>Closing of &#8216;the loop&#8217;</strong></p>
<p>The code looks like this:</p>
<p><code>&lt;?php else : ?&gt;<br />
&lt;?php endif; ?&gt;</code></p>
<p>Typically it&#8217;s on more than one line in case you want to build an option in, such as a message &#8220;Sorry, we didn&#8217;t find anything&#8221;. After the sidebar, before the sidebar and footer calls, is where you typically find the &#8220;next&#8221; and &#8220;previous&#8221; navigation links.</p>
<p><strong>Bastardized Loops?</strong></p>
<p>Well, just because most loops look like the examples I just gave you, doesn&#8217;t mean you can&#8217;t bastardize them in just about any way you can imagine. I recommend you read the WP Codex page <a href="http://codex.wordpress.org/The_Loop_in_Action">The Loop in Action</a> for examples of archive, category, and single post formats &#8211; as well as static home page.</p>
<p>The Codex official page for <a href="http://codex.wordpress.org/The_Loop">the loop</a> has several examples of how to place multiple loops in one page.</p>
<p>Perishable Press has a great tutorial for <a href="http://perishablepress.com/press/2008/09/01/multiple-loops-and-multiple-columns-with-wordpress/">multiple loops, multiple columns</a> &#8211; if you want to try and split your content up. They also have some great <a href="http://perishablepress.com/press/2007/11/14/easily-adaptable-wordpress-loop-templates/">loop templates</a>, in addition to a great tutorial of <a href="http://perishablepress.com/press/2008/08/04/two-column-horizontal-sequence-wordpress-post-order/">horizontally sequenced posts in two columns</a>.</p>
<h3>Conclusion</h3>
<p>Armed with just a tiny bit of knowledge, you can hack just about any WordPress theme template page to do just about whatever you want! Now that you understand (in great detail) how WordPress calls it&#8217;s pages and how the loop works, you can conquer any task! Have fun customizing your blog&#8217;s theme!</p>
<p><em>This post was submitted by John Pratt, who writes many <a href="http://www.jtpratt.com">Blogging Tips</a>, and how to create a <a href="http://www.jtpratt.com/series/wordpress-affiliate-store/">WordPress affiliate store</a>.</em></p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2029&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/how-to-hack-wordpress-theme-template-pages/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>How To: Use WordPress Conditional Tags to Hack Your Theme</title>
		<link>http://wphacks.com/wordpress-conditional-tags-hack-theme/</link>
		<comments>http://wphacks.com/wordpress-conditional-tags-hack-theme/#comments</comments>
		<pubDate>Wed, 13 May 2009 09:00:38 +0000</pubDate>
		<dc:creator>JTPratt Media</dc:creator>
				<category><![CDATA[Hacks]]></category>
		<category><![CDATA[How-To]]></category>
		<category><![CDATA[Tutorials]]></category>
		<category><![CDATA[Conditional Tags]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Conditional Tags]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[WordPress How-To]]></category>
		<category><![CDATA[WordPress Tips]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=2000</guid>
		<description><![CDATA[By using simple conditional tags &#8211; it&#8217;s pretty easy to add some very basic hacks to your WordPress theme to have more control over what&#8217;s displayed when. Here are some things you could do with a conditional tags: Display something only on certain pages Display something only on certain categories Display something in header and [...]]]></description>
			<content:encoded><![CDATA[<p>By using simple conditional tags &#8211; it&#8217;s pretty easy to add some very basic hacks to your WordPress theme to have more control over what&#8217;s displayed when.</p>
<p>Here are some things you could do with a conditional tags:</p>
<ul>
<li>Display something only on certain pages</li>
<li>Display something only on certain categories</li>
<li>Display something in header and footer only at certain times</li>
<li>Display something only on sub-children of particular pages</li>
<li>Display something only in the WP dashboard</li>
<li>Display something in the sidebar only when certain conditions are met</li>
<li>Do something only when there&#8217;s a &#8220;sticky&#8221; post</li>
<li>Do something only when a &#8220;page template&#8221; is used</li>
<li>Do something only for &#8220;author pages&#8221;</li>
<li>Display something only on search or 404 pages</li>
</ul>
<p>Let&#8217;s say you want something to display only on the homepage, or just category pages, or maybe just your 404 (not found) page &#8211; it&#8217;s quite easy to do.  You don&#8217;t have to be a hardcore programmer (I&#8217;m not for sure) to implement these very simple theme hacks.</p>
<h3>Where to Use Conditional Tags</h3>
<p>It all depends on your your theme is structured.  I&#8217;ve seen WordPress themes that a single &#8220;index.php&#8221; file handle just about everything, and other ones that use only the home.php, index.php, single.php, archive.php, and category.php files.  You could handle everything with a bunch of code in one file if you want using conditional tags, have individual files for each thing, or any combination in between.  </p>
<p>Most themes I&#8217;ve encountered usually have an index.php and a single.php only.  If you want to know what pages WordPress looks for first in a theme before defaulting to the &#8220;index.php&#8221;, read the official <a href="http://codex.wordpress.org/Template_Hierarchy">WordPress Template Hierarchy</a> page.</p>
<p>Conditional tags are great because you can use them both in and out of the loop.  You can use them directly in theme pages, but you could also use them in your header, footer, comments, and sidebar files.  Actually the sky is the limit, and you have only your own imagination to limit you!</p>
<h2>Conditional Tag Examples</h2>
<p>The worst thing I see on most posts about conditional tags is that they don&#8217;t have a lot of examples for you to draw from &#8211; so I&#8217;ll try to give you a few ideas to get you started&#8230;</p>
<h3>If This is XYZ page</h3>
<p>One of the most common ways to use a conditional tag is to add a filter of sorts to tell WordPress &#8220;if I&#8217;m on &#8216;XYZ&#8217; WP page &#8211; then do this.  The most common reason would be maybe to show certain things (ads, text, messages, graphics, scripts, flash) in certain places.</p>
<p>For example, let&#8217;s say you want to display a message to visitors on your home page only&#8230;</p>
<p><code>&lt;?php if (is_home()) { ?&gt;</p>
<p>Welcome, you will only see this message on my homepage!</p>
<p>&lt;?php } ?&gt;</code></p>
<p>replace &#8220;is_home&#8221; with &#8220;is_front_page&#8221;, &#8220;is_single&#8221;, &#8220;is_sticky&#8221;, &#8220;is_page&#8221;, &#8220;is_page_template&#8221;, &#8220;is_category&#8221;, &#8220;is_tag&#8221;, &#8220;is_author&#8221;, &#8220;is_date&#8221;, &#8220;is_archive&#8221;, or &#8220;is_attachment&#8221; to make your message show up on nearly any WordPress page.  Remember, once the condition is met, you can &#8220;do&#8221; anything &#8211; from including a file to showing special graphics, running a script, anything!  You could use this condition for example to show an ad on just your homepage, or just single pages.</p>
<h3>If this is XYZ page show this, else show that</h3>
<p>The nice thing about conditional tags is the fact that you can have as many conditions as you want&#8230;like this:</p>
<p><code><br />
&lt;?php if (is_home()) { ?&gt;</p>
<p>&lt;p&gt;Show this!&lt;/p&gt;</p>
<p>&lt;?php } elseif (is_single()) { ?&gt;</p>
<p>&lt;p&gt;Show this instead!&lt;/p&gt;</p>
<p>&lt;?php } elseif (is_category()) { ?&gt;</p>
<p>&lt;p&gt;Show something different!&lt;/p&gt;</p>
<p>&lt;?php else { ?&gt;</p>
<p>&lt;p&gt;Show this if no conditions are met&lt;/p&gt;</p>
<p>&lt;?php } ?&gt;</code></p>
<p>OR &#8211; you could even structure it in such a way that you lump some conditions together like this:</p>
<p><code>&lt;?php if (is home() || is_single() || is_category() || is_page()<br />
|| is_archive() { ?&gt;</p>
<p>&lt;p&gt;Show this on all those pages!&lt;/p&gt;</p>
<p>&lt;?php } ?&gt;</code></p>
<p>The double-pipe or || in the code signifies &#8220;OR&#8221;, so WordPress knows, if this is home, or a single page, or a category page, or a &#8220;page&#8221; page, or an archive page &#8211; then so something.</p>
<h3>Show Everywhere, Except&#8230;</h3>
<p>Sometimes you want to show something everywhere possible except just one or two places&#8230;</p>
<p><code>&lt;?php if (is_home()) {<br />
}<br />
else { ?&gt;</p>
<p>&lt;p&gt;Show this everywhere!&lt;/p&gt;</p>
<p>&lt;?php } ?&gt;</code></p>
<p>With this code we just say if it&#8217;s &#8220;home&#8221; do nothing, else show do this.  You could add multiple conditions (exclusions) to this using the || OR operator as in previous examples.</p>
<h3>Getting even more specific</h3>
<p>One thing I hadn&#8217;t mentioned was that you could pass additional parameters to the conditional tags for even finer grained control.  For example, instead of targeting are single post pages with &#8220;is_single&#8221;, you could actually target just one using any of these formats:</p>
<p>is_single(&#8217;25&#8242;) // uses posts ID<br />
is_single(&#8216;Title of my post&#8217;) //uses the exact title of the post<br />
is_single(&#8216;title-of-my-post&#8217;) //uses the permalink of the post<br />
is_single(array(25,&#8217;this title&#8217;,'this permalink&#8217;)) //uses when any of the 3 are true</p>
<p>You can use similar parameters for paged pages, template pages, categories, tags, etc.  The official <a href="http://codex.wordpress.org/Conditional_Tags">WordPress Conditional Tag page</a> in the Codex lists them all.</p>
<h3>Force WordPress Functions for Certain Conditions</h3>
<p>Have you ever not wanted to add people to your blogroll because their link will display on EVERY SINGLE page of your WP powered site?  That&#8217;s an easy hack with conditional tags, because you could hack your sidebar to display your blogroll ONLY on your homepage like this:</p>
<p><code>&lt;? php if (is_home()) {<br />
  wp_list_bookmarks();<br />
  }<br />
?&gt;</code></p>
<p>You could modify this to display just about anything in the sidebar for whatever conditions you want.  Let&#8217;s take this a bit further though &#8211; let&#8217;s say that maybe I want a special header or footer when certain conditions are met?  You can do that too&#8230;</p>
<p><code>&lt;? php if (is_home() || is_single() || is_page()) {<br />
  get_header();<br />
  }<br />
elseif (is_category() || is_tag()) {<br />
  include (TEMPLATEPATH . '/header2.php');<br />
}<br />
elseif (is_404() || is_search())<br />
  include (TEMPLATEPATH . '/header3.php');<br />
} ?&gt;</code></p>
<p>Using that example code you could have as many different headers, footers, or sidebars as you wanted and you could include them for whatever conditions you specified.  Just replace get_header with get_footer or get_sidebar, and edit the rest include the files you want.</p>
<h3>Using Conditional Tags to Change Styles</h3>
<p>So far my conditional tag examples have been to show you how code conditions to do this or include that.  Another very simple (and powerful) was to use conditional tags is to just use them for coding style.  You could have any element (paragraph, div, heading) change colors or font size or anything related to style when certain conditions are met.</p>
<p>Let&#8217;s take a very simple example, maybe your pages have content contained within one div like this:</p>
<p><code>  &lt;div id="content" class="main"&gt;<br />
	&lt;?php if (have_posts()) : ?&gt;<br />
		&lt;?php while (have_posts()) : the_post(); ?&gt;<br />
		&lt;?php endwhile; ?&gt;<br />
  &lt;/div&gt;</code></p>
<p>In most themes, that main &#8220;div&#8221; is styled the same way on EVERY single page of the theme.  Maybe you want it styled one way for your homepage, but another for paged pages, single posts, archives, etc.  What you do in this case is to write different classes in your stylesheet for each and call them something like &#8220;single&#8221;, &#8220;archive&#8221;, and &#8220;paged&#8221; &#8211; and then you code it like this:</p>
<p><code>  &lt;div id="content" &lt;?php if (is_home()) { ?&gt; class="home"<br />
&lt;?php } elseif (is_page()) { ?&gt; class="paged"<br />
&lt;?php } elseif (is_single()) ?&gt; class="single"<br />
&lt;?php } elsif (is_archive()) { ?&gt; class="archive" &lt;?php } ?&gt; &gt;<br />
	&lt;?php if (have_posts()) : ?&gt;<br />
		&lt;?php while (have_posts()) : the_post(); ?&gt;<br />
		&lt;?php endwhile; ?&gt;<br />
  &lt;/div&gt;</code></p>
<p>You use any variation of this to control any element of your theme at will under nearly any condition.  This would also be a great way to control your Post title and meta and have it display different things on different parts of your WordPress powered site.</p>
<h3>Conclusion</h3>
<p>I think mostly that the power of conditional tags is widely underutilized.  Many of us just take for granted the way a theme works and looks, and forget that with just a few strokes of code and some imagination &#8211; we can change just about anything under the sun in our WordPress theme!  I&#8217;d like to see some comments on what kinds of things you&#8217;ve used conditional tags for in your WordPress site (code samples welcomed!).</p>
<p><i>This post was submitted by John Pratt, who writes about how to <a href="http://www.jtpratt.com">Make Money Blogging</a>.  His latest post is <a href="http://www.jtpratt.com/how-to-build-a-wordpress-craigslist/">How to Build a WordPress Craigslist</a>.</i></p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=2000&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/wordpress-conditional-tags-hack-theme/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>How To: Prevent Images from Being to Large</title>
		<link>http://wphacks.com/how-to-prevent-images-from-being-to-large/</link>
		<comments>http://wphacks.com/how-to-prevent-images-from-being-to-large/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 17:09:51 +0000</pubDate>
		<dc:creator>Kyle Eslick</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[CSS Techniques]]></category>
		<category><![CDATA[WordPress Code]]></category>
		<category><![CDATA[WordPress Hacks]]></category>
		<category><![CDATA[Wordpress Images]]></category>
		<category><![CDATA[WordPress Themes]]></category>

		<guid isPermaLink="false">http://wphacks.com/?p=1904</guid>
		<description><![CDATA[Have you ever had an image show up on your website which is to large, causing problems for your WordPress theme?   This is especially common for WordPress blogs that have multiple authors, where some authors or guest posters may not know how big they can make the images. Fixing this is incredibly easy with this [...]]]></description>
			<content:encoded><![CDATA[<p>Have you ever had an image show up on your website which is to large, causing problems for your WordPress theme?   This is especially common for WordPress blogs that have multiple authors, where some authors or guest posters may not know how big they can make the images.</p>
<p>Fixing this is incredibly easy with this CSS hack!    All you need to do is take the following code and place it in your stylesheet, setting a maximum width for your images:</p>
<p><code>.postarea img {<br />
max-width: 500px;<br />
height: auto;<br />
}</code></p>
<p>In the above code snippet, you&#8217;ll want to replace postarea with whatever div ID or CLASS your theme uses for the content.   You can also adjust the 500px to the maximum width you&#8217;d like for your images to be.</p>
<p><strong>Note:</strong> This hack may not work on some versions of Internet Explorer.</p>
<img src="http://wphacks.com/?ak_action=api_record_view&id=1904&type=feed" alt="" />]]></content:encoded>
			<wfw:commentRss>http://wphacks.com/how-to-prevent-images-from-being-to-large/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.854 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-05-23 19:30:27 -->

