<?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>Web Do&#039;s &#38; Don&#039;ts &#187; Blog</title>
	<atom:link href="http://webdosanddonts.com/category/blog/feed" rel="self" type="application/rss+xml" />
	<link>http://webdosanddonts.com</link>
	<description>Tips&#38;Tricks for the modern day web designer</description>
	<lastBuildDate>Wed, 18 May 2011 22:30:13 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>HTML5 for Web Designers Mini Review</title>
		<link>http://webdosanddonts.com/html5-for-web-designers-mini-review</link>
		<comments>http://webdosanddonts.com/html5-for-web-designers-mini-review#comments</comments>
		<pubDate>Mon, 16 Aug 2010 08:32:21 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=1278</guid>
		<description><![CDATA[I recently read HTML5 for Web Designers by Jeremy Keith. Having spent not much time exploring HTML5 up to that point, I thought the book would be a good start. The outside With just 85 pages and a soft cover, the book was at first a slight disappointment, due to the fact I was not [...]]]></description>
			<content:encoded><![CDATA[<p><img style="float: right; padding: 0 0 20px 20px;" src="http://webdosanddonts.com/wp-content/uploads/2010/08/html5-for-web-designers.png" alt="" /> I recently read <a href="http://books.alistapart.com/product/html5-for-web-designers"><strong>HTML5 for Web Designers</strong> by <strong>Jeremy Keith</strong></a>. Having spent not much time exploring <strong>HTML5</strong> up to that point, I thought the book would be a good start.</p>
<h2 style="display: inline;">The outside</h2>
<p>With just 85 pages and a soft cover, the book was at first a slight disappointment, due to the fact I was not expecting such a <strong>thin book</strong>. The disappointment was short lived though, because a couple of hours into my train trip I was done and happily re-reading my favorite passages. The design of the book is very simple and very effective, as it makes the reader concentrate on its contents.</p>
<h2 style="display: inline;">The inside</h2>
<p>Once you start reading, you find the book is a joy to look at and read. You have to admire the excellent design, which in combination with a great paper quality guarantees <strong>a wonderful reading experience</strong>. But what makes it special is <strong>the way it was written</strong>&#8211;Jeremy Keith makes everything <strong>fun and super easy to understand</strong>. The author takes you on a quick trip from a brief history of markup to how you can use HTML5 <strong>today</strong>. I found myself nodding in acknowledgment several times and literally racing through pages. Simply put, this is one of those books that <strong>leaves you wanting more</strong>. After you are done, you just wish it had 50 extra pages.</p>
<h2 style="display: inline;">Conclusion</h2>
<p>I can recommend <strong>HTML5 for Web Designers</strong> to any of you who want to get familiar with HTML5. While it is not a book that will be your only resource on the topic, it will be <strong>a&nbsp;great introduction</strong> to a standard that is changing the World Wide Web. At $18 plus shipping it is not the cheapest book around, but worth it nevertheless. What I&#8217;d very much like to own is a PDF copy of the book, which is not (yet) available. This way, I would probably use it as a reference and not have to use Google instead.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/html5-for-web-designers-mini-review/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Fundamental PHP coding Do&#8217;s &amp; Don&#8217;ts</title>
		<link>http://webdosanddonts.com/fundamental-php-coding-dos-donts</link>
		<comments>http://webdosanddonts.com/fundamental-php-coding-dos-donts#comments</comments>
		<pubDate>Sun, 02 May 2010 21:00:26 +0000</pubDate>
		<dc:creator>Siniša</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=1151</guid>
		<description><![CDATA[There are tons of great PHP articles out there. Most of them cover performance tips and general PHP how-to&#8217;s. That&#8217;s why I&#8217;m going to take a different approach here and try to give you some PHP coding guidelines, many of which are just general good programming practices taken from the PHP perspective. Comment your code [...]]]></description>
			<content:encoded><![CDATA[<p>There are tons of great <a href="http://www.google.com/search?hl=en&#038;source=hp&#038;q=PHP+tips+%26+tricks&#038;aq=f&#038;aqi=&#038;aql=&#038;oq=&#038;gs_rfai=">PHP articles</a> out there. Most of them cover performance tips and general PHP how-to&#8217;s. That&#8217;s why I&#8217;m going to take a different approach here and try to give you some PHP coding guidelines, many of which are just general good programming practices taken from the PHP perspective.</p>
<h2>Comment your code in a formal standard</h2>
<p>Formatting comments in <a href="http://manual.phpdoc.org/HTMLSmartyConverter/HandS/phpDocumentor/tutorial_phpDocumentor.howto.pkg.html#basics.docblock">DocBlock</a> standard offers 3 main advantages to random commenting:</p>
<ul>
<li>It makes comments readable in a standard method encouraging programmers  to <strong>define and comment on aspects of the code that would normally be ignored</strong></li>
<li>It allows external document generators like <a title="PhpDocumentor" href="http://www.phpdoc.org/">phpDocumentor</a> to <strong>create well formatted and easy to understand documentation</strong></li>
<li>It allows some <a title="Integrated development environment" href="http://en.wikipedia.org/wiki/Integrated_development_environment">IDEs</a> to interpret variable types and other ambiguities in the loosely typed  language and to provide <strong>improved code completion, type hinting and  debugging</strong></li>
</ul>
<p>Here is an example of DocBlock comment:</p>
<pre><code>/**
 * A sample function docblock
 * @global string document the fact that this function uses $_myvar
 * @staticvar integer $staticvar this is actually what is returned
 * @param string $param1 name to declare
 * @param string $param2 value of the name
 * @return integer
 */
function firstFunc($param1, $param2 = 'optional')
{
    static $staticvar = 7;
    global $_myvar;
    return $staticvar;
}</code></pre>
<p>Commenting like this may take you some extra time, but it is worth it.</p>
<h2>Don&#8217;t overuse global variables</h2>
<p>&#8230; or better yet &#8212; try to keep them to the bare minimum if not avoiding them altogether :)</p>
<p>This is true for most (if not all) programming languages. Here&#8217;s what Wikipedia has to say on the subject:</p>
<blockquote><p>They are usually considered bad practice precisely because of their nonlocality: a global variable can potentially be modified from anywhere, (unless they reside in protected memory) and any part of the program may depend on it. A global variable therefore has an unlimited potential for creating mutual dependencies, and adding mutual dependencies increases complexity.</p></blockquote>
<p><cite><a href="http://en.wikipedia.org/wiki/Global_variable">Global variable on Wikipedia</a></cite></p>
<p>In PHP, global variables are used a little differently than in other languages. They must be declared global inside the function if they are going to be used in that function. I guess it&#8217;s a kind of safety mechanism protecting you from unintentionally changing a global variable. But on the other hand if you omit the global declaration by mistake you could end up spending hours on debugging, wondering why the output is not what (you think) it should be. Sounds familliar?</p>
<p>Some of the alternatives to global variables are:</p>
<ul>
<li> a static class, probably implementing a <a title="Example of Singleton pattern in PHP" href="http://www.php.net/manual/en/language.oop5.patterns.php#language.oop5.patterns.singleton">Singleton pattern</a></li>
<li>passing a variable as a parameter</li>
</ul>
<h2>Consider alternative syntax for control structures</h2>
<p>When using PHP control structures (<code>if</code>,<code> while</code>, <code>for</code>, <code>foreach</code>, <code>switch</code>) inside your HTML template those curlly brackets can really be hard to follow. Take a look at this HTML template extract:</p>
<pre><code>&lt;div id="fooes"&gt;
&lt;?php if ( have_foo() ) { ?&gt;
	&lt;h2&gt;Here are my fooes&lt;/h2&gt;
	&lt;?php foreach ( $fooes as $myfoo ) { ?&gt;
		&lt;h3&gt;&lt;?php echo $myfoo-&gt;title; ?&gt;&lt;/h3&gt;
		&lt;p class="foo-date"&gt;This foo was posted on &lt;?php echo $myfoo-&gt;date; ?&gt; by &lt;?php echo $myfoo-&gt;author; ?&gt;&lt;/p&gt;
		&lt;?php if ( $myfoo-&gt;is_special ) { ?&gt;
			&lt;div class="special"&gt;
				&lt;?php echo $myfoo-&gt;content; ?&gt;
			&lt;/div&gt;
		&lt;?php } else { ?&gt;
			&lt;div class="not-so-special"&gt;
				&lt;?php echo $myfoo-&gt;content; ?&gt;
			&lt;/div&gt;
		&lt;?php } ?&gt;
	&lt;?php } ?&gt;
&lt;?php } else { ?&gt;
	&lt;h2&gt;Sorry, no fooes available!&lt;/h2&gt;
&lt;?php } ?&gt;
&lt;/div&gt;</code></pre>
<p>Even in a simple template, like our example here, it&#8217;s easy to get confused with those closing brackets. So let&#8217;s try to rewrite this using <a href="http://php.net/manual/en/control-structures.alternative-syntax.php">alternative syntax for control structures</a>:</p>
<pre><code>&lt;div id="fooes"&gt;
&lt;?php if ( have_foo() ) : ?&gt;
	&lt;h2&gt;Here are my fooes&lt;/h2&gt;
	&lt;?php foreach ( $fooes as $myfoo ) : ?&gt;
		&lt;h3&gt;&lt;?php echo $myfoo-&gt;title; ?&gt;&lt;/h3&gt;
		&lt;p class="foo-date"&gt;This foo was posted on &lt;?php echo $myfoo-&gt;date; ?&gt; by &lt;?php echo $myfoo-&gt;author; ?&gt;&lt;/p&gt;
		&lt;?php if ( $myfoo-&gt;is_special ) : ?&gt;
			&lt;div class="special"&gt;
				&lt;?php echo $myfoo-&gt;content; ?&gt;
			&lt;/div&gt;
		&lt;?php else : ?&gt;
			&lt;div class="not-so-special"&gt;
				&lt;?php echo $myfoo-&gt;content; ?&gt;
			&lt;/div&gt;
		&lt;?php endif; ?&gt;
	&lt;?php endforeach; ?&gt;
&lt;?php else : ?&gt;
	&lt;h2&gt;Sorry, no fooes available!&lt;/h2&gt;
&lt;?php endif; ?&gt;
&lt;/div&gt;</code></pre>
<p>If you want a &#8220;real world&#8221; example take a look at the <a href="http://core.trac.wordpress.org/browser/branches/2.9/wp-content/themes/default/archive.php">archive.php template</a> from WordPress default theme.</p>
<h2>Avoid using PHP short tag</h2>
<p>Although there can be times when doing something like <code>&lt;?=$foo?&gt;</code> can seem like a convenient thing to do, you should resist the temptation and use <code>&lt;?php echo $foo; ?&gt;</code>.</p>
<p>There are several reasons why you should avoid using the PHP short tag, but here are the most important ones:</p>
<ul>
<li>On some shared hosts short tags are turned off so in case of  moving your site you might end up replacing all of your PHP opening tags</li>
<li>Avoid the confusion with the XML declaration</li>
<li><del title="I was wrong about this one. Short tags are here to stay :(" datetime="2010-05-08T00:00:00">Short tags will not be supported in future PHP versions</del></li>
</ul>
<h2>Initialize your variables</h2>
<p>Yes &#8212; PHP is loosely typed language and no &#8212; you don&#8217;t have to initalize your variables, but&#8230; Initializing variables (and sticking with it&#8217;s type from then on) is simply a good coding practice. This will make your code more easy to follow and less error-prone. Especially in larger functions/methods.</p>
<p>There is also a performace benefit since incrementing a initialized variable is much quicker then an uninitialized one.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/fundamental-php-coding-dos-donts/feed</wfw:commentRss>
		<slash:comments>29</slash:comments>
		</item>
		<item>
		<title>7 Essential Do&#8217;s &amp; Don&#8217;ts of Website Navigation</title>
		<link>http://webdosanddonts.com/7-essential-dos-donts-of-website-navigation</link>
		<comments>http://webdosanddonts.com/7-essential-dos-donts-of-website-navigation#comments</comments>
		<pubDate>Tue, 16 Mar 2010 10:39:00 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=951</guid>
		<description><![CDATA[An intuitive, easy to understand navigation is a crucial step towards good website usability. You can have awesome content, but if your visitors don&#8217;t know how to reach it, your content will also be close to useless. Your main goal is to ensure your visitors will find what they&#8217;re looking for as quickly and as [...]]]></description>
			<content:encoded><![CDATA[<p>An intuitive, easy to understand navigation is a crucial step towards good website usability. You can have awesome content, but if your visitors don&#8217;t know how to reach it, your content will also be close to <em>useless</em>. Your main goal is to ensure your visitors will find what they&#8217;re looking for <strong>as quickly and as easily as possible</strong>.</p>
<p>From the <a href="http://www.w3.org/TR/WCAG10/">Web Content Accessibility Guidelines</a>:</p>
<blockquote cite="http://www.w3.org/TR/WCAG10/"><p>Provide clear and consistent navigation mechanisms &#8212; orientation information, navigation bars, a site map, etc. &#8212; to increase the likelihood that a person will find what they are looking for at a site.</p></blockquote>
<p>To start things off, here&#8217;s an example of a well done navigation system: </p>
<div class="caption"><img src="http://webdosanddonts.com/wp-content/uploads/2010/03/croquis-nav.jpg" alt="Croquis.com's nav" />
<p>Navigation of <a href="http://www.thecroquis.com/process/">thecroquis.com/process/</a>.</p>
</div>
<p><a href="http://thecroquis.com/">The Croquis</a> does a fine job of making things clear and simple. Their menu can be easily spotted and the menu items send a clear message, avoiding any confusion. My only remark is that they did not omit the link to the <strong>process</strong> page <strong>on the process page</strong>. Instead, they just camouflaged it (try clicking <strong>Learn</strong>). </p>
<p>You&#8217;ll agree this is all common sense, but many designers fail to provide <strong>really&nbsp;usable</strong> navigation systems. Without further ado, let&#8217;s head onto our do&#8217;s and don&#8217;ts list.</p>
<h2>1. Do use the same navigational elements throughout the website</h2>
<p>Use the same navigation elements in the same or similar position on <strong>all pages within the website</strong>. Studies show users ignore the navigation and scan for fresh content when landing on a new page. Therefore, consistency is super important for the user experience. Users should always be able to quickly learn the navigation and adapt to the interface.</p>
<p>Therefore, remember to <strong>keep the navigation simple and constant</strong> throughout the website to avoid any confusion. Your users <strong>will</strong> thank you. The navigation is <strong>not</strong> the part of the site you want to get too clever with.</p>
<h2>2. Use clear names or icons for menu items</h2>
<p>Always use intuitive, clear and easy to understand text or icons in menus. <strong>Keep users from guessing</strong> what buttons, text or icons mean. If they need to click on a menu item and load the page to find out what the page is about, you&#8217;re not doing it right. Users who do not understand a certain part of a web page will most probably ignore it and continue to scan the page, or <strong>leave</strong>.</p>
<blockquote cite="http://uxmag.com/design/guiding-principles-for-ux-designers"><p>Make things simple and intuitive. Leave complexity to family dynamics, relationships, and puzzles. The things you create should be easy to use, easy to learn, easy to find, and easy to adapt.</p></blockquote>
<p><cite><a href="http://uxmag.com/design/guiding-principles-for-ux-designers">http://uxmag.com/design/guiding-principles-for-ux-designers</a></cite></p>
<h2>3. Highlight the current page</h2>
<p>Usability guru <a href="http://www.useit.com/">Jakob Nielsen</a> says you must tell your users where they can go, where they are and where they&#8217;ve been. This particular tip is about <strong>where the user is</strong>. This sort of feedback is crucial if you want to show your users where they are within your site.</p>
<p>Highlighting the current page is a simple trick with great benefits, but many fail to use it. Take a look at the menu bar of <a href="http://www.smashingmagazine.com/">Smashing Magazine</a>:</p>
<div class="caption"><img src="http://webdosanddonts.com/wp-content/uploads/2010/03/smashing-nav.jpg" alt="Smashing Mag's nav" />
<p>Navigation bar of <a href="http://www.smashingmagazine.com/">Smashing Magazine</a> site from the <a href="http://www.smashingmagazine.com/category/coding/">Coding page</a>.</p>
</div>
<p>Does this navigation bar tell you where you are? One could assume the current page is the home page, but in fact I clicked the Coding item before taking the screenshot. Here&#8217;s how the current item could be highlighted to tell the user where he is:</p>
<div class="caption"><img src="http://webdosanddonts.com/wp-content/uploads/2010/03/smashing-nav2.jpg" alt="Smashing Mag's nav" />
<p>My mockup of the Smashing Mag&#8217;s navigation with the highlighted item.</p>
</div>
<h2>4. Provide a search form</h2>
<p>Users often <strong>scan for the search form</strong> to help them find what they&#8217;re looking for. If they get lost or they think they will find what they&#8217;re looking for more quickly, they will use the search form. </p>
<p>Note that <em>very small sites</em> may not need the search feature, but any bigger site should have it.</p>
<p>Just this morning, I wanted to get more information on a feature my phone company introduced. I was very thankful the search form on their site was not only available in the header, but it worked <strong>just as I anticipated</strong>. It took me only one click, typing of a search query and hitting the enter key to get to the information I needed. <em>Awesome</em>. If the search form was not available at all, it would take me a whole lot of clicking through their rather complex navigation system. Or I would leave the site and tried a Google site-specific search (with <strong>site:</strong>).</p>
<p>Also remember to avoid text fields that don&#8217;t look like text fields and buttons that don&#8217;t look like buttons. Here&#8217;s an example how <strong>subtle</strong> gradients and shadows can make search elements much <em>more usable</em>:</p>
<div class="caption"><img src="http://webdosanddonts.com/wp-content/uploads/2010/03/searches.jpg" alt="Search elements with and without effects" />
<p>Two search forms styled differently. The second one is easier to use as it is communicating more clearly.</p>
</div>
<h2>5. Don&#8217;t link pages to themselves</h2>
<p>Omit the link that <a href="http://webdosanddonts.com/dont-link-pages-to-themselves">points to the current page</a>. This will only <strong>confuse your visitors</strong> and many will end up clicking on links that will lead them to the page they are on already.</p>
<p>This is another aspect which many, many sites could improve, including Smashing Magazine.</p>
<p><a href="http://powazek.com/">Derek Powazek</a> wrote a great article for <a href="http://www.alistapart.com/">ALA</a> which talks about this issue. Here&#8217;s a great quote from that article:</p>
<blockquote><p>The other day I was driving on the freeway. I was on the 120, going north, dutifully following my Mapquest directions, which said to get off on 120, and then turn right on 120. Say what? I thought I was on the 120 already. Am I lost?</p></blockquote>
<p><cite><a href="http://www.alistapart.com/articles/whereami">http://www.alistapart.com/articles/whereami</a></cite></p>
<p>Do provide clear instructions for your users and don&#8217;t allow them to <strong>spin around in circles</strong>.</p>
<h2>6. Don&#8217;t add mailto, Twitter or iTunes links or links to other sites to your main nav</h2>
<p>This was my main inspiration for writing this article. I don&#8217;t know about you, but I am treading <strong>very carefully</strong> when I am clicking through menu items on practically any new website I visit. You often see these menu items before you: <strong>Blog</strong>, <strong>Portfolio</strong>, <strong>About</strong>, <strong>Contact</strong>. Before clicking on <strong>Contact</strong>, my eyes go all the way down to the left bottom corner of my Safari and check <strong>where the link is pointed to</strong>. If the link is a <strong>mailto</strong> one, which is often the case, I won&#8217;t click it. I was not expecting a mailto link, but a page with contact info.</p>
<p>Here&#8217;s a screenshot from the lovely looking website of <a href="http://jackosborne.co.uk/">Jack Osborne</a>. </p>
<div class="caption"><img src="http://webdosanddonts.com/wp-content/uploads/2010/03/jackosborne.jpg" alt="Navigation menu of jackosborne.co.uk" />
<p>Navigation menu of <a href="http://jackosborne.co.uk/">http://jackosborne.co.uk/</a></p>
</div>
<p>I am expecting <strong>Contact</strong> leads to its own page, like <strong>Articles</strong>, <strong>Portfolio</strong> and <strong>About</strong> are. However, the contact link is a mailto link. A slight improvement would be to rename Contact into <strong>E-mail</strong>, but it is much better to make a Contact page or move the Contact link away from the others or style it differently.</p>
<p>Avoid grouping mailto, Twitter or iTunes links or links to other sites with the other menu items. At the very, very least, give the user <strong>some sort of a clue</strong> (like a tooltip) where he will end up. Think about what the user is expecting.</p>
<h2>7. Don&#8217;t use lengthy animations or transition effects</h2>
<p>Animations and transition effects can be appealing, <strong>if used sparingly</strong>. No-one wants to hover over a menu item and then wait for the animation to finish. Users want information and they want it <strong>instantly</strong>. Animations, if done well, are attractive, and you do want eye candy every now and then. But not at the expense of good usability. You want the users to <strong>focus on the content</strong>, not distract them.</p>
<p>Do you have some tips of your own to add to my list? I&#8217;d love to hear your thoughts. </p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/7-essential-dos-donts-of-website-navigation/feed</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>How to count posts in multiple categories for WordPress</title>
		<link>http://webdosanddonts.com/how-to-count-posts-in-multiple-categories-for-wordpress</link>
		<comments>http://webdosanddonts.com/how-to-count-posts-in-multiple-categories-for-wordpress#comments</comments>
		<pubDate>Sun, 29 Nov 2009 16:14:58 +0000</pubDate>
		<dc:creator>Siniša</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=581</guid>
		<description><![CDATA[As we promised in WebD&#38;D v2 introductory article, we&#8217;re doing a little series of articles about custom WordPress stuff we did to achieve certain features here on WebD&#38;D. So here is the first one of the series&#8230; One of the things that we needed throughout the site was a count of posts within various combinations [...]]]></description>
			<content:encoded><![CDATA[<p>As we promised in <a href="/introducing-webdd-version-two">WebD&amp;D v2 introductory article</a>, we&#8217;re doing a little series of articles about custom WordPress stuff we did to achieve certain features here on WebD&amp;D. So here is the first one of the series&#8230;<span id="more-581"></span></p>
<p>One of the things that we needed throughout the site was a count of posts within various combinations of categories. Unfortunately, that kind of feature isn&#8217;t supported in WordPress out-of-the-box. We&#8217;ll get a little technical here so those of you who just want the final solution&#8211;feel free to fast forward to the end of the article and grab the code.</p>
<h2>How we did it</h2>
<p>WordPress is, as you probably know, a database driven platform, so first thing we need to do is to identify the right <a title="Wordpress database diagram" href="http://codex.wordpress.org/File:WP_27_dbsERD.png">tables and understand their relationships</a> in order to retrieve the correct data from them.</p>
<p>Basically our goal here is to identify terms that have taxonomy <em>&#8216;category&#8217;</em> and filter the ones we&#8217;re interested in. For filtering only specific categories well need to join <em>terms</em> table. Then we have to find out which posts belong to those categories. That&#8217;s why we&#8217;ll join the <em>wp_term_relationships</em> table. And last but not least, we&#8217;ll throw <em>posts</em> table to the mix.</p>
<p>Let&#8217;s say we wanted to count all posts from &#8220;Advanced&#8221; and &#8220;Intermediate&#8221; categories. Assuming that table prefix is the default one, our SQL query should look something like:</p>
<pre><code>SELECT	COUNT( DISTINCT cat_posts.ID ) AS post_count
FROM 	wp_term_taxonomy AS cat_term_taxonomy INNER JOIN wp_terms AS cat_terms ON
		cat_term_taxonomy.term_id = cat_terms.term_id
	INNER JOIN wp_term_relationships AS cat_term_relationships ON
		cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id
	INNER JOIN wp_posts AS cat_posts ON
		cat_term_relationships.object_id = cat_posts.ID
WHERE 	cat_posts.post_status = 'publish' AND
	cat_posts.post_type = 'post' AND
	cat_term_taxonomy.taxonomy = 'category' AND
	cat_terms.slug IN ('advanced', 'intermediate')</code></pre>
<p>The name of the <em>posts</em> table is somewhat misleading because it contains not only posts but pages, post revisions, and whatnot&#8230; Hence the condition <code>post_type = 'post'</code>. Being picky like we are, we only want published posts so we expanded our condition with a little <code>post_status = 'publish'</code>.</p>
<p>Another thing I want to point out is the <code>COUNT DISTINCT</code>&#8230; A well know feature in WordPress is that a post can belong to any number of categories so without counting only distinct post IDs we could end up with a wrong (much bigger) count.</p>
<p>Now we&#8217;ll change that query a bit and wrap it in a PHP function. That will allow us to pass any number of category slugs.</p>
<pre><code>function wdd_in_category_count($catslugs = '', $display = true) {
	global $wpdb;

	$post_count = 0;
	$slug_where = '';
	$catslugs_arr = split(',', $catslugs);

 	foreach ($catslugs_arr as $catslugkey => $catslug) {
		if ( $catslugkey > 0 ) {
			$slug_where .= ', ';
		 }

 		$slug_where .= "'" . trim($catslug) . "'";
	}

	$slug_where = "cat_terms.slug IN (" . $slug_where . ")";

	$sql =	"SELECT	COUNT( DISTINCT cat_posts.ID ) AS post_count " .
		"FROM 	" . $wpdb->term_taxonomy . " AS cat_term_taxonomy INNER JOIN " . $wpdb->terms . " AS cat_terms ON " .
				"cat_term_taxonomy.term_id = cat_terms.term_id " .
			"INNER JOIN " . $wpdb->term_relationships . " AS cat_term_relationships ON " .
				"cat_term_taxonomy.term_taxonomy_id = cat_term_relationships.term_taxonomy_id " .
			"INNER JOIN " . $wpdb->posts . " AS cat_posts ON " .
				"cat_term_relationships.object_id = cat_posts.ID " .
		"WHERE 	cat_posts.post_status = 'publish' AND " .
			"cat_posts.post_type = 'post' AND " .
			"cat_term_taxonomy.taxonomy = 'category' AND " .
			$slug_where;

	$post_count = $wpdb->get_var($sql);

	if ( $display ) {
		echo $post_count;
	} 

	return $post_count; 

}
</code></pre>
<p>Our little function here has a <code>$catslugs</code> input parameter that expects category slugs in a string separated with commas. We also used <code>$wpdb</code> variables instead of hard coding the table names, witch is always a good practice.</p>
<h2>How can you use it</h2>
<p class="download"><a href="http://webdosanddonts.com/wp-content/uploads/2009/11/wdd_in_category_count.zip">Download Multiple category post counter function for WordPress</a></p>
<p>First download the code, uncompress and paste it somewhere in your functions.php file. Then find the place in your template file where you want to display number of posts form certain categories and call the <code>wdd_in_category_count()</code> function.</p>
<p>For example, if you had a movie review blog and you wanted to display number of reviews for Horror and SF movies, put something like this:</p>
<pre><code>&lt;p&gt;Total number of Horror and SF reviews: &lt;?php wdd_in_category_count('sf, horror') ?&gt;.&lt;/p&gt;</code></pre>
<p>And there you have it&#8230; That&#8217;s how you count <del datetime="2009-11-29T15:15:21+00:00">sheep</del> posts within multiple categories.</p>
<p>Please reply with your questions, comments and suggestions.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/how-to-count-posts-in-multiple-categories-for-wordpress/feed</wfw:commentRss>
		<slash:comments>18</slash:comments>
		</item>
		<item>
		<title>Introducing WebD&amp;D, version two</title>
		<link>http://webdosanddonts.com/introducing-webdd-version-two</link>
		<comments>http://webdosanddonts.com/introducing-webdd-version-two#comments</comments>
		<pubDate>Sun, 22 Nov 2009 22:19:47 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=746</guid>
		<description><![CDATA[When we started this site in early May, we knew exactly what we wanted&#8211;a super, super simple site with a very usable layout. We&#8217;ve done just that and WebD&#38;D, we&#8217;re happy to say, was a great success. As the site grew in content, we needed to rethink and rebuild and fairly soon we started working [...]]]></description>
			<content:encoded><![CDATA[<p>When we started this site in early May, we knew exactly what we wanted&#8211;a super, super simple site with a very usable layout. We&#8217;ve done just that and WebD&amp;D, we&#8217;re happy to say, was <strong>a great success</strong>. As the site grew in content, we needed to rethink and rebuild and fairly soon we started working on version two.</p>
<p>From day one, we also wanted to add a lot of features to the site. With <strong>v2</strong>, we&#8217;re finally introducing some of those new features. We&#8217;ll let you discover those, of which some are not obvious at first glance.</p>
<p>Design-wise, we&#8217;ve not gone far away from version one. What we hope we have done is spice things up a little bit, making the site more visually attractive. We&#8217;ve stuck to the familiar, neutral color scheme and the lovely <a href="http://www.dardenstudio.com/typefaces/omnes">Omnes typeface</a>.</p>
<p>WebD&amp;D is still running on <a title="WordPress - Blog Tool and Publishing Platform" href="http://wordpress.org">WordPress</a>, spiced with some custom made code to achieve exactly what we wanted. The most fun was writing some custom SQL queries for all tag-category combinations and getting variable number of posts (tips and blog) for any category combination. We plan to share the acquired knowledge and experience in future articles. So stay tuned.</p>
<p>We also used some of the sweet plugins available:</p>
<ul>
<li><a title="WP Super Cache" href="http://ocaoimh.ie/wp-super-cache/">WP Super Cache</a></li>
<li><a title="Yet Another Related Posts Plugin" href="http://mitcho.com/code/yarpp/">Yet Another Related Posts Plugin</a></li>
<li><a title="WP-PostRatings" href="http://lesterchan.net/portfolio/programming/php/">WP-PostRatings</a></li>
<li><a title="Twitter for WordPress" href="http://rick.jinlabs.com/code/twitter">Twitter for WordPress</a></li>
<li><a title="All in One SEO Pack" href="http://wordpress.org/extend/plugins/all-in-one-seo-pack/">All in One SEO Pack</a></li>
</ul>
<p>This time around, as far as JavaScripting goes, we really took advantage of the excellent <a title="jQuery" href="http://jquery.com/">jQuery</a> framework with some cool plugins. In all our laziness we used:</p>
<ul>
<li><a title="TableSorter" href="http://tablesorter.com/docs/">TableSorter</a></li>
<li><a title="ColorBox" href="http://colorpowered.com/colorbox/">ColorBox</a></li>
</ul>
<p>We don&#8217;t want to keep you away from browsing the site a second longer. We hope you enjoy <strong>WebD&#038;D v2</strong>. Let us know what you think in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/introducing-webdd-version-two/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>15 Twitter Netiquette Rules You Must Know</title>
		<link>http://webdosanddonts.com/15-twitter-netiquette-rules-you-must-know</link>
		<comments>http://webdosanddonts.com/15-twitter-netiquette-rules-you-must-know#comments</comments>
		<pubDate>Tue, 25 Aug 2009 11:07:21 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=572</guid>
		<description><![CDATA[Whether you are familiar with Twitter or you are just starting to learn what a great networking tool it is, you must get to know how it really works to communicate well and make use of its potential. People use Twitter for many things, but the same rules apply for everyone. Misuse and abuse of [...]]]></description>
			<content:encoded><![CDATA[<p>Whether you are familiar with Twitter or you are just starting to learn what a great networking tool it is, you must get to know how it <strong>really</strong> works to communicate well and make use of its potential. People use Twitter for many things, but the same rules apply for everyone. Misuse and abuse of Twitter is not at all uncommon and even the experienced twitterers often don&#8217;t follow the <strong>netiquette</strong>.</p>
<p>Here are <strong>15 tips</strong> on how to tweet politely and avoid getting <strong>unfollowed</strong>.<span id="more-572"></span></p>
<h2>1. Provide your name, avatar and a short bio</h2>
<p>Always include your name and a short bio in your Twitter profile. People want to know <strong>who you are</strong>. Do not hide behind false names. Be honest if you expect honesty. Make sure to use your photo or a custom avatar so others can remember and recognize you.</p>
<h2>2. Be social</h2>
<p><strong>Be social</strong> and <strong>interact</strong>. Make your tweets personal and let your followers get to know you. Kindly reply if someone asks you a question. Feel free to ask questions zourself and connect with people. Share interesting links with the community (but be sure to check they actually work). After all, Twitter is a <strong>social network</strong>. </p>
<h2>3. Be moderate in self-plugging</h2>
<p>There&#8217;s nothing wrong with the occasional self-plug, but don&#8217;t keep a Twitter account just to promote your work. Although many people use Twitter simply to publish site news, that is <strong>not</strong> what Twitter is about. </p>
<h2>4. No auto direct messages, please</h2>
<p>Auto direct messages are a big <strong>no-no</strong>, even if you are just being nice and saying hi to someone who has just started following you. What auto messages are really saying is &#8220;I don&#8217;t have the time to be really polite so I&#8217;ll just send and auto DM to everyone&#8221;. Also, no one is expecting a DM when they start following you. </p>
<h2>5. Give credit</h2>
<p>When you find a useful information somewhere, be it a tweet, a blog post or a picture you want to share, <strong>give credit</strong> by letting people know who it was that led you to your discovery. If you read a tweet you want to share with others, a simple retweet will do. </p>
<p><a href="http://twitter.com/iA/statuses/3526325519"><img src="http://webdosanddonts.com/wp-content/uploads/2009/08/ia-tweet.png" alt="Screenshot of a tweet from iA" width="400" height="191" class="alignnone size-full wp-image-648 post-pic-alt" /></a></p>
<h2>6. Don&#8217;t use twitter for chatting or personal conversation</h2>
<p>Twitter is not an instant messenger. Not only it is not as effective as IM is, but others <strong>don&#8217;t</strong> really want to read through multiple tweets of your personal conversation. Instead of making private conversations public, use <strong>direct messages</strong> (or e-mail or an IM client). </p>
<h2>7. Your post should not span through multiple tweets</h2>
<p>A tweet should contain up to 140 characters. That&#8217;s 140, and not a character more. Don&#8217;t write messages that are <strong>more than one tweet long </strong>and continue your message in the next tweet. Move longer posts to appropriate mediums, like <a href="http://posterous.com/">Posterous</a>, <a href="http://www.tumblr.com/">Tumblr</a>, or your blog.</p>
<h2>8. Don&#8217;t tweet too much</h2>
<p>Twitter is all about <strong>quick and easy messages</strong>. Try not to tweet too much or your followers might not want to read all what you have to say. For me, reading dozens of tweets and retweets a day from a single person is too much. Choose <strong>quality over quantity</strong>. If you suspect you might be tweeting too much, a good idea might be to ask your followers what they think. </p>
<h2>9. Don&#8217;t flood</h2>
<p>While there are people who are interested in reading dozens of your tweets one after the other, most are not. <strong>Flooding</strong> is not polite so try not to overdo it. If your followers have too much to read and explore, they might easily choose to ignore your tweets.</p>
<h2>10. Follow, unfollow and block whoever you wish</h2>
<p>On Twitter, you are free to follow and unfollow whoever you wish. You&#8217;re also free to block people from viewing your tweets. When someone follows you, you are <strong>not obligated</strong> to follow them back. When someone unfollows you, it does not mean you have to unfollow them. Unfollowing someone does not mean &#8220;I don&#8217;t like you&#8221;. </p>
<h2>11. Do not follow everyone who follows you</h2>
<p>Do not follow <strong>everyone</strong> who follows you, just for the sake of it. What good is it to follow thousands of people if you aren&#8217;t really following their tweets? Most users who follow thousands of people are considered to be <strong>spammers</strong>. </p>
<h2>12. Use hashtags, but do not overuse them</h2>
<p><strong>Hashtags</strong> aren&#8217;t really effective if every word in a tweet is a hashtag. Use them <strong>sparingly</strong> to help people find information without making the message look spammy. </p>
<p><a href="http://twitter.com/umutm/status/3532217620"><img src="http://webdosanddonts.com/wp-content/uploads/2009/08/umut-tweet.png" alt="" class="alignnone size-full wp-image-648 post-pic-alt" /></a></p>
<h2>13. Do not spam</h2>
<p><strong>Never spam</strong> on Twitter and do not send people unwanted information. People will unfollow you if you keep asking them to retweet your posts, help you reach a certain number of followers or if you are retweeting contest tweets all of the time. Open a second Twitter account if you like the contests that require retweeting. </p>
<h2>14. Provide enough information</h2>
<p>When you tweet, make sure you provide enough information. Simply copy/pasting an URL is <strong>not enough</strong>. Add value to your tweets and make them <strong>easy to understand and scan</strong>. </p>
<h2>15. Retweet in 140 characters</h2>
<p>Sometimes a retweet will not fit inside the 140 chars limit once you add the @username. To make it fit, <strong>cut the last part </strong>of the message. If you think it will not make a lot of sense like that, change the text but try to keep it as similar to the original as possible. What you are basically doing is quoting someone else, so be fair.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/15-twitter-netiquette-rules-you-must-know/feed</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>CushyCMS giweaway winner</title>
		<link>http://webdosanddonts.com/cushy-cms-giweaway-winner</link>
		<comments>http://webdosanddonts.com/cushy-cms-giweaway-winner#comments</comments>
		<pubDate>Tue, 11 Aug 2009 08:34:34 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=562</guid>
		<description><![CDATA[As promised, today we are announcing the winner of the CushyCMS giveaway! A 12 month subscription to CushyCMS Pro, worth over $330, goes to Spain and Jose Vittone! Congratulations to Jose and thanks to Leigh from Stateless Systems. Thanks to all the participants, stay tuned for more giveaways on WebD&#038;D.]]></description>
			<content:encoded><![CDATA[<p>As promised, today we are announcing the winner of the <a href="http://webdosanddonts.com/cushycms-giveaway">CushyCMS giveaway</a>!</p>
<p>A 12 month subscription to <a href="http://www.cushycms.com/">CushyCMS Pro</a>, worth over $330, goes to Spain and <a href="http://josevittone.com/"><strong>Jose Vittone</strong></a>! Congratulations to Jose and thanks to <a href="http://twitter.com/leighhanney">Leigh</a> from <a href="http://www.statelesssystems.com/">Stateless Systems</a>.</p>
<p>Thanks to all the participants, stay tuned for more giveaways on WebD&#038;D.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/cushy-cms-giweaway-winner/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>CushyCMS giveaway</title>
		<link>http://webdosanddonts.com/cushycms-giveaway</link>
		<comments>http://webdosanddonts.com/cushycms-giveaway#comments</comments>
		<pubDate>Wed, 05 Aug 2009 08:37:18 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=543</guid>
		<description><![CDATA[Try your luck in our very first giveaway! We&#8217;re giving you an opportunity to win a 12 month subscription to CushyCMS Pro, worth over $330! CushyCMS is a simple content management system powering over 30000 websites. Maybe you&#8217;ll manage your website with it soon as well. To enter our contest, all you need to do [...]]]></description>
			<content:encoded><![CDATA[<p> Try your luck in our very first <strong>giveaway</strong>! We&#8217;re giving you an opportunity to win a 12 month subscription to <strong><a href="http://www.cushycms.com/">CushyCMS Pro</a></strong>, worth <strong>over $330</strong>! CushyCMS is a simple content management system powering over 30000 websites. Maybe you&#8217;ll manage your website with it soon as well.</p>
<p>To enter our contest, all you need to do is: </p>
<ol>
<li>Post a comment in this post, answering <strong>Why would a free 12 month CushyCMS Pro subscription be cool?</strong>
<li><a href="http://twitter.com/home/?status=RT:+@webdosanddonts+Win+a+Free+CushyCMS+Pro+subscription!+http://tr.im/vxDS">Tweet the CushyCMS giveaway</a></li>
</ol>
<p>The giveaway is open until <strong>August 10, 2009</strong>. We&#8217;ll be chosing the lucky winner with a random generator on <strong>August 11</strong> after which <a href="http://twitter.com/leighhanney">Leigh</a> from <a href="http://www.statelesssystems.com/">Stateless Systems</a> will be providing you with the licence. Best of luck to all of you. </p>
<p>More giveaways will follow so be sure to <a href="http://twitter.com/webdosanddonts/">follow us on Twitter</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/cushycms-giveaway/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>Introducing the WebD&amp;D blog</title>
		<link>http://webdosanddonts.com/introducing-the-webdd-blog</link>
		<comments>http://webdosanddonts.com/introducing-the-webdd-blog#comments</comments>
		<pubDate>Tue, 04 Aug 2009 15:24:39 +0000</pubDate>
		<dc:creator>Bojan</dc:creator>
				<category><![CDATA[Blog]]></category>

		<guid isPermaLink="false">http://webdosanddonts.com/?p=520</guid>
		<description><![CDATA[From today, the WebD&#038;D blog is officially open. Welcome! On our blog, we&#8217;ll be covering all web design and development related topics. Of course, we&#8217;re also open to any of the suggestions you may have. What would you want us to write about? How would you make our site better? What features would you like [...]]]></description>
			<content:encoded><![CDATA[<p>From today, the <strong>WebD&#038;D blog</strong> is officially open. Welcome!</p>
<p>On our blog, we&#8217;ll be covering all web design and development related topics. Of course, we&#8217;re also open to any of the suggestions you may have. What would you want us to write about? How would you make our site better? What features would you like to see? As always, you are more than welcome to comment on our site and make your voice count.</p>
<p>We also have a <strong>giveaway</strong> ready for all our readers, so stay tuned and enter the competition soon.</p>
<p>Last, but not least, we&#8217;d like to thank our sponsor, <a href="http://wpwebhost.com/">WPWebHost</a>, because it&#8217;s the sponsors that keep WebD&#038;D alive. </p>
]]></content:encoded>
			<wfw:commentRss>http://webdosanddonts.com/introducing-the-webdd-blog/feed</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 0.898 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2013-05-24 12:09:34 -->
