<?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>Les James &#124; Design &#38; Stuff &#187; wordpress</title>
	<atom:link href="http://lesjames.com/tag/wordpress/feed/" rel="self" type="application/rss+xml" />
	<link>http://lesjames.com</link>
	<description>Les James is a web designer and beer fan. CSS and brown ales make him happy.</description>
	<lastBuildDate>Wed, 04 Aug 2010 19:09:44 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Templating WordPress Image Attachments</title>
		<link>http://lesjames.com/373/templating-wordpress-image-attachments/</link>
		<comments>http://lesjames.com/373/templating-wordpress-image-attachments/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 01:58:28 +0000</pubDate>
		<dc:creator>Les</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lesjames.com/?p=373</guid>
		<description><![CDATA[Wordpress doesn't come with any native tags to template post attachments so I came up with a function to help. Simply include a chunk of code in your functions.php file and call the function from inside the loop. The function returns and array with multiple pieces of info about your post attachments.]]></description>
			<content:encoded><![CDATA[<p>One of the problems I&#8217;ve encountered while templating for WordPress is the lack of tags for post attachments. I want full control over how post images appear in my template and I don&#8217;t want to use WordPress&#8217;s &#8220;Insert into post&#8221; which simply inserts an attachment into the post content. So I hit up Google and came across some code by <a href="http://www.rlmseo.com/blog/get-images-attached-to-post/">John Crenshaw</a>. He created a function to write out the first image attachment for a post. I needed something more powerful than that but I love the way he bubble sorted the attachments so that I could use WordPress&#8217;s attachment order in my template. Here is the first part of the function that grabs the post attachments, resorts them and creates an array.</p>
<pre><code>
// Get images for this post
$arrImages =&#038; get_children('post_type=attachment&#038;post_mime_type=image&#038;post_parent=' . get_the_ID() );

// If images exist for this page
if($arrImages) {

// Get array keys representing attached image numbers
$arrKeys = array_keys($arrImages);

// Put all image objects into new array with standard numeric keys
foreach($arrImages as $oImage) {
	$arrNewImages[] = $oImage;
}

// Bubble sort image object array by menu_order
for($i = 0; $i < sizeof($arrNewImages) - 1; $i++) {
	for($j = 0; $j < sizeof($arrNewImages) - 1; $j++) {
		if((int)$arrNewImages[$j]->menu_order > (int)$arrNewImages[$j + 1]->menu_order) {
			$oTemp = $arrNewImages[$j];
			$arrNewImages[$j] = $arrNewImages[$j + 1];
			$arrNewImages[$j + 1] = $oTemp;
		}
	}
}

// Reset arrKeys array
$arrKeys = array();

// Replace arrKeys with newly sorted object ids
foreach($arrNewImages as $oNewImage) {
	$arrKeys[] = $oNewImage->ID;
	$captions[] = $oNewImage->post_excerpt;
}
</code></pre>
<p>After an ordered array of post attachments is created I wrote some code to create a new array with data about each attachment. I pull data for the image&#8217;s thumbnail url, full size url, caption, width, height and ID. Here is how the array is built&#8230;</p>
<pre><code>
// Build image array
for ($i=0; $i < sizeof($arrKeys); $i++){
	$iNum = $arrKeys[$i];

	// get various image sizes
	$image_thumb = wp_get_attachment_image_src($iNum, $size='thumbnail');
	// $image_large = wp_get_attachment_image_src($iNum, $size='large');
	$image_full = wp_get_attachment_image_src($iNum, $size='full');

	// store image thumbnail(0) and full url(1)
	$image_service[$i][0] = $image_thumb[0];
	$image_service[$i][1] = $image_full[0];

	// store image caption(2)
	$image_service[$i][2] = $captions[$i];

	// get the image dimensions
	// store image width(3) and height(4)
	$image_service[$i][3] = $image_full[1];
	$image_service[$i][4] = $image_full[2];	

	// get attachment id
	$image_service[$i][5] = $iNum;
}
</code></pre>
<p>Here is the full function to place in your functions.php file: <a href="http://gist.github.com/466100">WordPress Post Attachments Function</a></p>
<p>All of this only builds an array for you. None of it places an attachment into your template. To do that you just need to call the function inside of the loop and place the array data where you need it. To call the first image attachment, say for adding a thumbnail to the post excerpt on your homepage you just need to pull the thumb url from the array we built earlier.</p>
<pre><code>
&lt;?php $image_service = gallery_images(); ?&gt;

&lt;figure&gt;&lt;img alt="&lt;?php echo $image_service[0][2]; ?&gt;" src="&lt;?php echo $image_service[0][0]; ?&gt;" /&gt;&lt;/figure&gt;
</code></pre>
<p>Notice the array has two dimensions. The first one in this case is [0], meaning we are pulling the first attachment from the array (remember that arrays start with zero). You can see in the alt tag the second dimension is [2] because this is the position we stored the attachment caption. The source of the img tag uses [0][0] which calls the first attachment's thumbnail url. Getting how this works?</p>
<p>So what about pulling more than one image? To do this we just need to make a loop and cycle through our array like this...</p>
<pre><code>
&lt;?php for($i = 0; $i &lt; sizeof($image_service); $i++) { ?&gt;

&lt;figure&gt;&lt;img alt="&lt;?php echo $image_service[$i][2]; ?&gt;" src="&lt;?php echo $image_service[$i][0]; ?&gt;" /&gt;&lt;/figure&gt;

&lt;?php } ?&gt;
</code></pre>
<p>Replacing the array's first dimension with [$i] from the loop allows you to pull all of the attachments for your post.</p>
<p>If you need different layouts for horizontal or vertical photos just pull the image width [3] or height [4], do your if statement math and template away. Using the loop allows you to easily create your own gallery too. Wrap an anchor tag around a thumbnail image and link to the full size url to create an easy, template generated thickbox. Since WordPress generates a thumbnail, medium and large size for everything you upload it's easy to grab different media types. You can see where I commented out the large image media type. Just add another array position to have access to it. Remember that if you are going to template different media sizes set your image dimensions in WordPress under Settings -> Media.</p>
<p>Hit me up if you have any questions and if you find a way to improve this code please share it.</p>
]]></content:encoded>
			<wfw:commentRss>http://lesjames.com/373/templating-wordpress-image-attachments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Creating a Lifestream</title>
		<link>http://lesjames.com/204/creating-a-lifestream/</link>
		<comments>http://lesjames.com/204/creating-a-lifestream/#comments</comments>
		<pubDate>Mon, 03 Aug 2009 19:25:15 +0000</pubDate>
		<dc:creator>Les</dc:creator>
				<category><![CDATA[Social Media]]></category>
		<category><![CDATA[blogging]]></category>
		<category><![CDATA[lifestream]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lesjames.com/?p=204</guid>
		<description><![CDATA[I have been giving some thought as to the direction of this site. 90% of this site&#8217;s design is centered about a blog. It doesn&#8217;t take long to notice that I don&#8217;t blog very often. So I have been playing with the idea of turning this site into a lifestream. The design would give equal [...]]]></description>
			<content:encoded><![CDATA[<p>I have been giving some thought as to the direction of this site.  90% of this site&#8217;s design is centered about a blog.  It doesn&#8217;t take long to notice that I don&#8217;t blog very often.  So I have been playing with the idea of turning this site into a lifestream.  The design would give equal weight to these things:</p>
<ul>
<li>Blog</li>
<li>Portfolio</li>
<li>Twitter</li>
<li>Delicious</li>
<li>Pandora</li>
<li>Blippr</li>
<li>Flickr</li>
</ul>
<p>So in one place you could see things that I write, work on, tweet, read, listen to, use and take pictures of.  I would like to keep everything grouped together instead of being a true blended lifestream.  So how would I accomplish this?  I just started playing around with <a href="http://friendfeed.com/lesjames">FriendFeed</a> today.  I&#8217;m not a pro yet but I don&#8217;t like the blended feed that it creates but the ability to comment on each individual item is cool. </p>
<p>The other method I stumbled upon to create a lifesteam is from Yahoo called <a href="http://pipes.yahoo.com/lesjames/lifestream">Yahoo Pipes</a>.  Its complex, powerful and cool all at the same time.  You import data from anywhere you can grab it and send that data through pipes to different modules and filters.  In the end I&#8217;m left with a very customizable lifestream.  The only question is how do I get that stream on my website in a way that allows me total control over it&#8217;s presentation.  It will be something to work on for sure, but this does mean that this site will probably go through another redesign.  You knew it was going to happen, it was only a matter of time.  Four months to be exact.  Ugh!</p>
<p>Stay tuned, I&#8217;m sure I can knock this out by next week.</p>
]]></content:encoded>
			<wfw:commentRss>http://lesjames.com/204/creating-a-lifestream/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Breaking Away From Viewport</title>
		<link>http://lesjames.com/184/breaking-away-from-viewport/</link>
		<comments>http://lesjames.com/184/breaking-away-from-viewport/#comments</comments>
		<pubDate>Mon, 15 Jun 2009 19:21:08 +0000</pubDate>
		<dc:creator>Les</dc:creator>
				<category><![CDATA[css3]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[usability]]></category>
		<category><![CDATA[viewport]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lesjames.com/?p=184</guid>
		<description><![CDATA[This site&#8217;s design is reaching a crossroads. I am starting to remove major elements of the Viewport theme in a move to increase the site&#8217;s usability and layout aesthetics. This move is being done with special category templates for the web and interactive sections of my portfolio. I have removed the sliding panels and opted [...]]]></description>
			<content:encoded><![CDATA[<p>This site&#8217;s design is reaching a crossroads.  I am starting to remove major elements of the Viewport theme in a move to increase the site&#8217;s usability and layout aesthetics.  This move is being done with special category templates for the web and interactive sections of my portfolio.  I have removed the sliding panels and opted to have projects tile themselves down the page.  In addition each category archive now pulls in special page content that serves as a description.  A note about this description, I&#8217;m using CSS3 columns for the first time.  Safari and Firefox users will now see eye friendly columns instead of a super wide block of text.  The key now is to actually fill these portfolio sections with projects.</p>
<p>This brings me a decision on what to do with the blog category and the homepage.  For now I&#8217;m going to to keep the sliding panels but I think it can be done better.  I&#8217;m thinking that on the homepage I want to try and figure out a way to include only the latest blog post and then start listing out my favorite portfolio projects.  I am also going to add a panel at the end that will list out my most recent blog and twitter posts.  As for the blog archive I&#8217;m going to have to think of a new presentation but I suppose what&#8217;s in place now will suffice.  Time to start hacking the home page!</p>
]]></content:encoded>
			<wfw:commentRss>http://lesjames.com/184/breaking-away-from-viewport/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Viewport Theme</title>
		<link>http://lesjames.com/31/viewport-theme/</link>
		<comments>http://lesjames.com/31/viewport-theme/#comments</comments>
		<pubDate>Fri, 01 May 2009 15:58:04 +0000</pubDate>
		<dc:creator>Les</dc:creator>
				<category><![CDATA[css]]></category>
		<category><![CDATA[template]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[viewport]]></category>
		<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lesjames.com/?p=31</guid>
		<description><![CDATA[Update: June 22, 2010: I am no longer using the Viewport Theme on my site. If you have a question about your Viewport Theme or WordPress in general feel free to shoot me a message through Twitter. Archived Post&#8230; I finally had a little time to work on this site. Wouldn&#8217;t you know I&#8217;ve thrown [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Update: June 22, 2010:</strong><br />
I am no longer using the Viewport Theme on my site. If you have a question about your Viewport Theme or WordPress in general feel free to shoot me a message <a href="http://twitter.com/lesjames">through Twitter</a>.</p>
<h3>Archived Post&#8230;</h3>
<p>I finally had a little time to work on this site.  Wouldn&#8217;t you know I&#8217;ve thrown my lj design under the bus.  Well kind of.  I am now using the Viewport theme as my base template and skinning it with elements from my lj theme.  I&#8217;m applying this skin as a child template of Viewport and so far things are running pretty smooth.  So far I&#8217;ve only changed the header and footer templates and of course, I have a new style sheet to override the parent theme.  I like the Viewport theme because it&#8217;s perfect for a portfolio site.  I&#8217;m going to create custom pages that will group my various projects together.  General blog entries will have a default blog image that I have yet to draw.</p>
<p>Hopefully this will be the last change in direction for the theme of this site.  I want to customize the hell out of Viewport and make it my own.  Hopefully I will be able to find the time.</p>
<p>Update: May 29, 2009:</p>
<p>I&#8217;ve noticed a couple people landing on this page since it&#8217;s ranking high with a search for Viewport Theme.  So I&#8217;ll try to spell out everything I&#8217;ve done to customize it.  First off all the changes I&#8217;ve made hae been through a child theme.  This way I can customize the theme one part at a time.  If I haven&#8217;t created an override in the child theme WordPress then defaults to the actual Viewport theme files.  This ensures that if I miss something it won&#8217;t break the theme.</p>
<p>I started with the header and footer.  Since these don&#8217;t really have anything to do with the actual &#8220;viewport&#8221; they are completely customized to look like my original site design.  The header does contain conditional code to activate jQuery links depending on what page you are on.  I did have to add is_search() to the conditional statement because it wasn&#8217;t in the original header for some reason.</p>
<p>Since the Viewport theme is based on pictures I needed to come up with a default blog picture that could be automatically added when I don&#8217;t specify a picture for the post.  I changed the php code to check if the post viewport picture is blank and if so place my default blog pic in there instead.  I also made the pic appear as a css background-image so that I could round the corners of the container div and apply a box shadow (which currently only shows in Safari).  I made these changes to the index, single, archive and search template files.</p>
<p>I made a lot of changes to the single template (which controls the post page).  I took out the top and bottom divs that used to house rounded corner images in favor of a single div with css rounded corners.  I made lots of css style changes and added my Twitter status to the sidebar with Twitter Widget Pro.</p>
<p>I&#8217;ll revisit this post if I make and further Viewport specific customizations.</p>
<p>Update: <a href="http://lesjames.com/breaking-away-from-viewport/">June 15th 2009</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lesjames.com/31/viewport-theme/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Constructing lj</title>
		<link>http://lesjames.com/1/constructing-lj/</link>
		<comments>http://lesjames.com/1/constructing-lj/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 15:43:51 +0000</pubDate>
		<dc:creator>Les</dc:creator>
				<category><![CDATA[wordpress]]></category>

		<guid isPermaLink="false">http://lesjames.com/?p=1</guid>
		<description><![CDATA[So I have the database set up and the initial theme files in place. There are still a few bugs to work out like commenting forms and image pre-loading, but for the most part the blog is fairly functionional. This is the first WordPress theme that I have built from scratch so it&#8217;s taking me [...]]]></description>
			<content:encoded><![CDATA[<p>So I have the database set up and the initial theme files in place.  There are still a few bugs to work out like commenting forms and image pre-loading, but for the most part the blog is fairly functionional.  This is the first WordPress theme that I have built from scratch so it&#8217;s taking me a little while to learn the ins and outs.  Once I have finished polishing the blog section of this site I&#8217;ll start working on the portfolio section.</p>
]]></content:encoded>
			<wfw:commentRss>http://lesjames.com/1/constructing-lj/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
