Make Column with PHP and CSS


We are always use column if we are create gallery page or magazine page. There is to way to make it happen, first you can use tag HTML and CSS, but it will be manual. you must set one by one of the tag to make it. And the second way is using PHP and CSS, with this way you can make it to be automatically, you just create variable to set how many column as you like.

I already create it in PHP for WordPress page Template, but if you want use it without WordPress, you just change the query.Ok let try this code:

 <?php query_posts( '&paged='.$paged); ?> 

<?php $itemsPerRow = 3; $i=1; $rows_part = 0; $counts = 1; $padding = 1; ?> 

<?php if (have_posts()) : ?> 

<div> <?php while (have_posts()) : the_post(); ?> 

<?php if ($rows_part == 0) { ?> 

<div> <?php $rows_part = 1; } ?> 

<div style="width:150px;<?php if ($padding == 2){?>margin:0px 10px;<?php }?>"> 

<?php the_excerpt(); ?> 

</div> 

<?php if ($i % $itemsPerRow == 0){ $rows_part = 0; $padding = 0;?> </div> <?php } 

$counts=$i; $i++; $padding++; ?> 

<?php endwhile; ?> 

<?php if ($counts % $itemsPerRow != 0){ ?> </div> <?php } ?> 

</div> 

<?php endif; ?> 

If you have other suggest or any error with this code please tell me in the comment.
Thanks all….

Advertisements

One thought on “Make Column with PHP and CSS

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s