<?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>James Whittaker &#187; wordpress</title>
	<atom:link href="http://jameswhittaker.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://jameswhittaker.com</link>
	<description>Front-end Developer, Designer and Consultant</description>
	<lastBuildDate>Sat, 19 Sep 2009 17:36:02 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>8 Top Tips for Wordpress Theme development</title>
		<link>http://jameswhittaker.com/journal/8-top-tips-for-wordpress-theme-development/</link>
		<comments>http://jameswhittaker.com/journal/8-top-tips-for-wordpress-theme-development/#comments</comments>
		<pubDate>Fri, 30 Jan 2009 10:48:42 +0000</pubDate>
		<dc:creator>jmwhittaker</dc:creator>
				<category><![CDATA[journal]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://jameswhittaker.com/?p=236</guid>
		<description><![CDATA[
Having moved this blogs CMS from ExpressionEngine to Wordpress 2.7 , I wanted to design and develop my own theme. You can start from blank canvas themes however I chose to start completely from scratch primarily so that I could get a good idea about how things work in Wordpress.

I did hit a few roadblocks [...]]]></description>
			<content:encoded><![CDATA[<p><img src="http://jameswhittaker.com/wordpress/wp-content/uploads/2009/01/banner-wordpress.jpg" alt="Wordpress tips" title="Wordpress tips" width="535" height="150" class="bdr" /></p>
<p>Having moved this blogs CMS from ExpressionEngine to Wordpress 2.7 , I wanted to design and develop my own theme. You can start from blank canvas themes however I chose to start completely from scratch primarily so that I could get a good idea about how things work in Wordpress.</p>
<p><span id="more-236"></span></p>
<p>I did hit a few roadblocks during development and what follows are a few tip that could help you out if your creating your own theme.</p>
<h4>Adding a body tag ID dynamically</h4>
<p>There are times when it&#8217;s really useful to alter styling between pages using an ID on the body tag that can then be targeted via CSS. In Wordpress this get&#8217;s a little tricky as pages are repurposed like single.php. So I created a new function in my functions.php file to dynamically assign preset ID&#8217;s to selected pages.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> jmw_body_class<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$print</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wp_query</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// Generic semantic classes for what type of content is displayed</span>
	is_archive<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>     	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgArchive'</span>    	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_date<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>        	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgDate'</span>       	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>      	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgSearch'</span>     	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_paged<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>       	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgPaged'</span>      	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>			? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgPage'</span>		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Journal'</span><span style="color: #009900;">&#41;</span>	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgJournal'</span>		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'About'</span><span style="color: #009900;">&#41;</span>	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgAbout'</span>		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Projects'</span><span style="color: #009900;">&#41;</span>	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgProjects'</span>	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_page<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Contact'</span><span style="color: #009900;">&#41;</span>	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgContact'</span>		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>  	 	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgPost'</span> 		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span>	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgJournal'</span>		<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Single page for Journal entries</span>
	in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'11'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'8'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'10'</span><span style="color: #009900;">&#41;</span> ? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgProjects'</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
	is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>        	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpgHome'</span>       	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// For the blog posts page, if set</span>
	is_404<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>         	? <span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'bpg404'</span>     	<span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// CSS does not allow a digit as first character</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$print</span> ? <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$c</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>You would call this from your header.php template file like this:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;body id='<span style="color: #000000; font-weight: bold;">&lt;?php</span> jmw_body_class<span style="color: #009900;">&#40;</span>  <span style="color: #009900;">&#41;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>'&gt;</pre></div></div>

<p>The code should be clear, what we are doing is using Wordpress&#8217;s functions to determine what page is being called. The standard ones are there, then I have added my own specifically for this site. I have page files like Journal and Projects that I can identify using the is_page() function.</p>
<p>Watch the order of items. This is because is_single() will fire for every single page and as I have separate single pages depending upon the category of the post. So by adding an in_category() rule after is_single() I can target the singles page for those category posts.</p>
<h4>Better SEO page titles</h4>
<p>It&#8217;s always a good idea to have the best semantic page titles you can. For SEO purposes your title tag should be unique to each page, so you want to include things like the post title, what page you are on if your paging through archives and possibly your sites name.</p>
<p>I always place my site name at the end of any title, apparently this is better for the likes of Google but more importantly better for people bookmarking your page &#8211; the content is described first followed by your sites name.</p>
<p>So like the example above it&#8217;s into your functions.php file to add something similar to:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> jmw_page_title<span style="color: #009900;">&#40;</span> <span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$paged</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// is the current page a tag archive page?</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #990000;">function_exists</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'is_tag'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> is_tag<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span> 
		<span style="color: #666666; font-style: italic;">// if so, display this custom title</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Tag Archive for &amp;quot;'</span><span style="color: #339933;">.</span><span style="color: #000088;">$tag</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;quot; - '</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">// or, is the page an archive page?</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_archive<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
		<span style="color: #666666; font-style: italic;">// if so, display this custom title</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Archive for '</span><span style="color: #339933;">.</span>wp_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">// or, is the page a search page?</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_search<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
		<span style="color: #666666; font-style: italic;">// if so, display this custom title</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Search for &amp;quot;'</span><span style="color: #339933;">.</span>wp_specialchars<span style="color: #009900;">&#40;</span><span style="color: #000088;">$s</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">'&amp;quot; - '</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">// or, is the page a single post or a literal page?</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span>is_404<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">&amp;&amp;</span> <span style="color: #009900;">&#40;</span>is_single<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">||</span> <span style="color: #009900;">&#40;</span>is_page<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span> 
&nbsp;
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> wp_title<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span><span style="color: #009900; font-weight: bold;">false</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">// or, is the page an error page?</span>
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_404<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">// yep, you guessed it</span>
	<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;opps, sorry I'm a 404 error page - &quot;</span><span style="color: #339933;">;</span> 
&nbsp;
	<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$c</span> <span style="color: #339933;">=</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">' - '</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'description'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
	<span style="color: #009900;">&#125;</span> 
&nbsp;
	<span style="color: #666666; font-style: italic;">//Shows what page your on</span>
&nbsp;
&nbsp;
&nbsp;
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$paged</span> <span style="color: #339933;">&gt;=</span> <span style="color: #cc66cc;">2</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>	
	 	<span style="color: #000088;">$c</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot; page &quot;</span><span style="color: #339933;">.</span> <span style="color: #000088;">$paged</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>	
&nbsp;
	<span style="color: #666666; font-style: italic;">// finally, display the blog name for all page types</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span>is_home<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>	<span style="color: #000088;">$c</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$pagenum</span> <span style="color: #339933;">.</span>  <span style="color: #0000ff;">' &amp;raquo; '</span> <span style="color: #339933;">.</span> get_bloginfo<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #b1b100;">print</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$c</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The just include the following PHP in your header.php file:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;title&gt;<span style="color: #000000; font-weight: bold;">&lt;?php</span> jmw_page_title<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000000; font-weight: bold;">?&gt;</span>&lt;/title&gt;</pre></div></div>

<p>Take a look at the title&#8217;s on this site for an example of how this works.</p>
<h4>Load category specific single post page</h4>
<p>This is covered by many other Wordpress theme blogs. I wanted to have a differently structured page for my single project posts compared to my single journal posts. Wordpress will naturally open up single.php when asked to serve up a single post.</p>
<p>The key is to remove all content from the single.php page and include the appropriate single page depending upon the post category:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">	<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
	<span style="color: #666666; font-style: italic;">// Journal entries</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'4'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> 
	<span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/single-journal.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
	<span style="color: #666666; font-style: italic;">//Projects</span>
	<span style="color: #b1b100;">elseif</span> <span style="color: #009900;">&#40;</span>in_category<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'11'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>	
		<span style="color: #b1b100;">include</span><span style="color: #009900;">&#40;</span>TEMPLATEPATH <span style="color: #339933;">.</span> <span style="color: #0000ff;">'/single-projects.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span> 
	<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>This is small but the theory is that you can have differently structured pages for each category if you so wished. It&#8217;s worth saying that if you have the same page structure and you just wanted to load up different CSS just follow the same principle above.</p>
<h4>Fixing the more tag</h4>
<p>When it comes to limiting a posts output like on the homepage, you use a number of methods. There is the standard the_excerpt or the common the_excerpt_reloaded (plugin) or you could just use the more option. Many themes use the_excerpt_reloaded to limit content based upon character length and tags whilst still retaining valid XHTML tags. This didn&#8217;t work exactly how I wanted so I reverted back to using the more option in the Wordpress editor.</p>
<p>Problem was it was failing within some of my custom loops. So here is a fix that works:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
	<span style="color: #666666; font-style: italic;">//Fix to get the more tag to work properly</span>
	<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$more</span><span style="color: #339933;">;</span>
	<span style="color: #000088;">$more</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
	the_content<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Using additional stylesheets</h4>
<p>As a good web developer you will no doubt have the need to include more than one style sheet into your theme. A standard Wordpress theme will have style.css in the theme folder root and you could use the @import rule in that CSS file to load extra style files for modern browsers. However you may want to include a print or handheld media stylesheet or even use IE conditional comments for loading in additional CSS.</p>
<p>Simple you just need to get the URL address path for your theme at runtime:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; media=&quot;print&quot; href=&quot;<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> get_template_directory_uri<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>/styles/print.css&quot; /&gt;</pre></div></div>

<h4>Target the first post in a list</h4>
<p>Using the loop you can style or alter the markup for the first post (or any number in reality). This might be useful in your theme to allow more text or have a larger layout than the rest of the posts in alist.</p>
<p>This is easily done without using any plugins like this, add a new php variable before your loop code ($count in this example):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=1&amp;showposts=5&amp;order=DESC'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #000088;">$count</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #b1b100;">while</span> <span style="color: #009900;">&#40;</span>have_posts<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> the_post<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Now in your code for writing out the content you can use that new variable in a conditional, not forgetting to increase the counter afterwards:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$count</span> <span style="color: #339933;">==</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	// You different code for the first post goes here
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">else</span> <span style="color: #339933;">:</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>
	// If the count is greater than 1 then this will be used
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">endif</span><span style="color: #339933;">;</span> <span style="color: #000088;">$count</span><span style="color: #339933;">++;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Fixing broken paging links</h4>
<p>Depending upon your permalink structure Wordpress (at least with version 2.7) can break your paging links at the bottom of a post. This solution worked although I could not get it to fully work when using a custom homepage. If you have any suggestions please leave them in the comments.</p>
<p>When calling your custom query pass through a page variable:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span> query_posts<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'cat=4&amp;posts_per_page=5&amp;paged='</span><span style="color: #339933;">.</span><span style="color: #000088;">$paged</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<h4>Wordpress security</h4>
<p><a href="http://www.smashingmagazine.com/2009/01/26/10-steps-to-protect-the-admin-area-in-wordpress/">SmashingMagazine.com</a> recently had a great series of articles on how to make your Wordpress installation more secure. I have followed a number of these suggestions, they are well worth a look.</p>
<p>In following one of the suggestions to rename your table prefix from wp_ to something a little more obscure and random, I hit a bit of trouble. Basically this should ideally be done when you first install wordpress. However I had already start my Wordpress site so had to do it retrospectively. </p>
<p>Following <a href="http://tdot-blog.com/wordpress/6-simple-steps-to-change-your-table-prefix-in-wordpress">this guide</a>, I managed to change the database tables. However I could not log into the admin interface. To get around this you also need to change any values inside wp_options table, look for wp_user_roles and change the wp_ bit to your new table_prefix.</p>
<h4>In conclusion</h4>
<p>I have really enjoyed working with Wordpress on my site redevelopment. ExpressionEngine was becoming very clunky and is starting to show it&#8217;s age, the new EE2.0 has some tough competition. With some tweaking Wordpress is very capable as a CMS. It is not without it&#8217;s oddities and some of the UX in the admin area is a little questionable. But if you fancy rolling up your sleeves and getting dirty with a bit of PHP then you can achieve great things with Wordpress.</p>
]]></content:encoded>
			<wfw:commentRss>http://jameswhittaker.com/journal/8-top-tips-for-wordpress-theme-development/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
