Tuesday, December 06, 2011
Easiest to make two columns in Wordpress
Searching around on the internet I found a few solutions to the problem I faced, but I felt they were more complicated then they needed to be. The problem was I had a list of posts and i wanted to display them in two columns in alphabetical order. Here was my solution.
First thing i did was I made variable called $rowcount outside of the wordpress loop, like this:
1. $rowcount = 0;
Secondly, I add a div for my left column outside of the loop.
2. <div style=“float:left; width:40%;”>
Thirdly, inside of the loop I incremented the $rowcount variable like this:
3. $rowcount++; // incrememnt rowcount var
Fourth, a simple if statement looking for rowcount 17 and close the initial div and open a new div.
4. if ($rowcount == 17 ) {
echo "</div><div style='float:left; width:40%;'>";
}
5. Fifth, I output the content i wanted from the posts.
6. I closed up the loop.
7. I close the div outside of the loop.
Probably the easiest way to make 2 columns.