<?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>TransformationPowerTools &#187; wordpress loop</title>
	<atom:link href="http://www.transformationpowertools.com/wordpress/tag/wordpress-loop/feed" rel="self" type="application/rss+xml" />
	<link>http://www.transformationpowertools.com/wordpress</link>
	<description>for personal growth and transformation</description>
	<lastBuildDate>Fri, 20 Jan 2012 13:23:43 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Multi-Column Grid-Style Posts in WordPress</title>
		<link>http://www.transformationpowertools.com/wordpress/multi-column-wordpress-template</link>
		<comments>http://www.transformationpowertools.com/wordpress/multi-column-wordpress-template#comments</comments>
		<pubDate>Fri, 29 Jan 2010 11:33:36 +0000</pubDate>
		<dc:creator>alchymyth</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[3 column post]]></category>
		<category><![CDATA[grid]]></category>
		<category><![CDATA[grid layout]]></category>
		<category><![CDATA[grid style]]></category>
		<category><![CDATA[magazine style]]></category>
		<category><![CDATA[multi-column]]></category>
		<category><![CDATA[portofolio]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[thumbnail grid]]></category>
		<category><![CDATA[wordpress loop]]></category>
		<category><![CDATA[wordpress theme]]></category>

		<guid isPermaLink="false">http://www.transformationpowertools.com/wordpress/?p=517</guid>
		<description><![CDATA[a flexible solution to a grid style layout for a wordpress theme - multi-column with a preset number of rows - inspired by re-occurring questions in the wordpress support forum. custom programmed queries to adjust for pagination.
by alchymyth <a href="http://www.transformationpowertools.com/wordpress/multi-column-wordpress-template">Check the whole post <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p><strong><em>RECOMMENDATION:<br />
as this code can have its challenges, and is not always easy to apply, i would like to point to an easier to implement approach with the same results (depending on formatting):<br />
<a href="http://www.transformationpowertools.com/wordpress/playing-with-columns-stacking-posts-grid-style">Playing with columns – stacking posts in a grid</a>.<br />
There is also a newer article for <a href="http://www.transformationpowertools.com/wordpress/posts-in-columns-a-new-twist-on-an-old-problem">creating posts in three columns</a>.</em><br />
</strong></p>
<p>Following question comes up regularly in the wordpress support forum: &#8216;i want to show my posts in three (four, five) columns, how can i do it?&#8217;</p>
<p>see the effect here in action: under <strong>pages </strong><a href="http://www.transformationpowertools.com/wordpress/grid-posts">&#8216;grid of posts&#8217;</a>.</p>
<p>here, i am going  to present yet another solution: a flexible core structure to allow <strong>any</strong> number of columns with <strong>any </strong>number of rows, limited only by screen space, readability and fantasy&#8230;</p>
<div id="attachment_683" class="wp-caption aligncenter" style="width: 522px"><img class="size-large wp-image-683" title="grid-style-template" src="http://www.transformationpowertools.com/wordpress/wp-content/uploads/2010/01/grid-style-template-512x375.jpg" alt="a three column grid category template" width="512" height="375" /><p class="wp-caption-text">a three column grid category template</p></div>
<p>the structure (for instance 3 columns, 4 rows, 12 or more posts):<br />
<strong>
<pre>
1  5   9
2  6  10
3  7  11
4  8  12</pre>
<p></strong></p>
<p>the structure (for instance 3 columns, 4 rows, less than 12 posts, i.e. 7):<br />
<strong>
<pre>
1  4  6
2  5  7
3 </pre>
<p></strong></p>
<p>the code is setup step by step:</p>
<ol>
<li>setting of variables</li>
<li>query_posts</li>
<li>calculate rows</li>
<li>loop 1 &#8211; the columns</li>
<li>the wordpress loop &#8211; the rows</li>
<li>page navigation</li>
</ol>
<p>here is the full code:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php get_header(); ?&gt;
&lt;?php
// code to display a number of posts in multi columns top-to-bottom left-to-right
?&gt;
&lt;?php global $query_string; ?&gt;
&lt;?php
$set_number_of_columns = 2; // enter numbers of columns here;
$set_number_of_rows = 4; // enter numbers of rows here
$set_showpost = $set_number_of_columns * $set_number_of_rows ;
//setup query with parameter for paged
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
query_posts($query_string.'&amp;showposts='.$set_showpost.'&amp;paged='.$paged);
// get number of posts for this,
$num_of_posts = $wp_query-&gt;post_count;
// make adjustment for paged to get three equaly long columns even on last paged page
// divide by $set_number_of_columns to get number per column,
// round up to next integer to make $ppc posts per column variable, or $set_number_of_rows whatever is smaller
$ppc = min(ceil($num_of_posts/$set_number_of_columns),$set_number_of_rows);
// calculates number of rows, i.e. showposts for the following query_posts and get_posts
?&gt;
&lt;?php for ( $col = 1; $col &lt;= $set_number_of_columns; $col += 1) { ?&gt;
&lt;div class=&quot;col&lt;?php echo $col;?&gt;&quot;&gt;
&lt;?php
$row = 1;
$noffset = ($col -1) * $ppc + ($paged - 1) * $set_showpost ; //calculate offset parameter if paged
$posts = get_posts($query_string.'&amp;numberposts='.$ppc.'&amp;offset='.$noffset);
foreach ($posts as $post) : start_wp(); ?&gt;
&lt;div id=&quot;post-&lt;?php the_ID(); ?&gt;&quot; class=&quot;post row-&lt;?php echo ($row%2); ?&gt;&quot;&gt;
&lt;!-- start of anything to do with post --&gt;
&lt;h2&gt;
&lt;a href=&quot;&lt;?php the_permalink() ?&gt;&quot; rel=&quot;bookmark&quot;&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt;
&lt;div class=&quot;storycontent&quot;&gt;
&lt;?php the_excerpt(__('(more...)')); ?&gt;
&lt;/div&gt;
&lt;!-- end of anything to do with post --&gt;
&lt;/div&gt; &lt;!-- end #post --&gt;
&lt;?php
$row++;
endforeach; ?&gt;
&lt;/div&gt;
&lt;?php } ?&gt;
&lt;?php // close the for-loop // ?&gt;
&lt;div class=&quot;navigation&quot;&gt;
&lt;div class=&quot;alignleft&quot;&gt;&lt;?php next_posts_link('&amp;laquo; Older Entries') ?&gt;&lt;/div&gt;
&lt;div class=&quot;alignright&quot;&gt;&lt;?php previous_posts_link('Newer Entries &amp;raquo;') ?&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;?php get_footer(); ?&gt;</pre>
<p>the naming of the css classes is:<br />
class .col1 for the first column; class .col2 for the second column; and so forth.<br />
same thing for the rows: class .row1 for the posts in first row, on so on.<br />
going with this code is the css:</p>
<pre class="brush: css; title: ; notranslate">.col1, .col2 {float:left; width:49%; }</pre>
<p>you can see the code in action: under <strong>pages </strong><a href="http://www.transformationpowertools.com/wordpress/grid-posts">&#8216;grid of posts&#8217;</a>.<br />
the effect ia achieved by giving each post a fixed height; and using a bit of javascript trickery.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.transformationpowertools.com/wordpress/multi-column-wordpress-template/feed</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>More-Than-Zebra style wordpress loop</title>
		<link>http://www.transformationpowertools.com/wordpress/zebra-style-wordpress-loop</link>
		<comments>http://www.transformationpowertools.com/wordpress/zebra-style-wordpress-loop#comments</comments>
		<pubDate>Thu, 14 Jan 2010 00:50:58 +0000</pubDate>
		<dc:creator>alchymyth</dc:creator>
				<category><![CDATA[Easy Coding for Wordpress]]></category>
		<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[alternating styles]]></category>
		<category><![CDATA[custom theme]]></category>
		<category><![CDATA[forum]]></category>
		<category><![CDATA[logic]]></category>
		<category><![CDATA[modification]]></category>
		<category><![CDATA[php code]]></category>
		<category><![CDATA[theme]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[wordpress loop]]></category>

		<guid isPermaLink="false">http://www.transformationpowertools.com/wordpress/?p=591</guid>
		<description><![CDATA[wordpress theme modifications: examples of how to programm alternating styles in the wordpress loop, how to style the first -or the last - post different, even how to create posts with three alternating styles. to use it in any situation in your wordpress templates, where you loop through some output - lists, foreach, for, while, posts, comments, ...  <a href="http://www.transformationpowertools.com/wordpress/zebra-style-wordpress-loop">Check the whole post <span class="meta-nav">&#187;</span></a>]]></description>
			<content:encoded><![CDATA[<p>to start, i would like to express my thanks and gratitude to all the volunteers in the <a href="http://wordpress.org/support/">wordpress forum</a> who patiently and freely give their time and attention, and share their knowledge and experience with all the users coming with questions and problems about their wordpress installation and modifications.<br />
a great community.</p>
<p>lists or posts styled with alternating color backgrounds, for instance, can inprove the readability of blogs.</p>
<p>most themes and the standard wordpress installation are not offering this feature.<br />
however, it is easy to implement, when you know how.</p>
<p>for example we could give alternating posts within the &#8216;wordpress loop&#8217; a different extra class (&#8216;odd&#8217; or &#8216;even&#8217;) which can then be used with css.<br />
to begin with, we introduce a counter ($c = 0;) before the loop, increment it inside the loop ($c++), and generate a class depending on the number of the counter by checking the modulus 2 of the number ($c % 2 &#8211; modulus is the remainder of the division):</p>
<pre class="brush: php; title: ; notranslate">&lt;?php $c = 0 ; ?&gt;
&lt;?php if (have_posts()) : while (have_posts()) : the_post(); ?&gt;
&lt;?php $c++;
if( $c % 2 == 0 ) $extra_class = ' even';
else $extra_class = ' odd'; ?&gt;
&lt;div class=&quot;post &lt;?php echo $extra_class; ?&gt;&quot;&gt;
&lt;!--typical stuff in the loop--&gt;
&lt;/div&gt;
&lt;?php endwhile; ?&gt;
&lt;?php else : endif; ?&gt;</pre>
<p>the class &#8216;odd&#8217; or &#8216;even&#8217; can be used in the style.css to create different background colors, alignments, margins, paddings, font-styles &#8211; no limits.</p>
<p>the most basic application of this method with a counter is how to style the first post in the loop different (only showing the logic part of the code):</p>
<pre class="brush: php; title: ; notranslate">&lt;?php $c++;
if( $c == 1 ) $extra_class = ' first';
else $extra_class = ''; ?&gt;</pre>
<p>to make it more interesting, the next example is to create three different styles and a special style for the last post on the page.<br />
we can get the number of the last post with</p>
<pre class="brush: php; title: ; notranslate">$wp_query-&gt;post_count </pre>
<p>The structure is the same, the main difference is in the &#8216;if, elseif, else&#8217; logic:</p>
<pre class="brush: php; title: ; notranslate">&lt;?php $c++;
if( $c == $wp_query-&gt;post_count ) $extra_class = ' last';
elseif( $c % 3 == 0 ) $extra_class = ' three';
elseif( $c % 3 == 2 ) $extra_class = ' two';
elseif( $c % 3 == 1 ) $extra_class = ' one';
?&gt;</pre>
<p>you can extend this method to create any number of cyclic classes.</p>
<p>and you can use it in any situation in your wordpress templates, where you loop through some output &#8211; lists, foreach, for, while, posts, comments, &#8230;</p>
<p>special thanks to <a href="http://profiles.wordpress.org/esmi/">@esmi</a> who dared venturing into the realm of more than two alternating styles, and who inspired me to post this article.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.transformationpowertools.com/wordpress/zebra-style-wordpress-loop/feed</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

