Ok so here's the deal..... I want to get posts from a category in Wordpress and divide all posts in that category into 4 vertical columns evenly. I've tried offsetting posts and putting them into columns but the problem is that this is not efficient and requires tweaking when new posts are added. <ul> <li> <?php global $post; $theseposts = get_posts('cat=5,-20,-21&order=desc&numberposts=3&offset=3'); foreach($theseposts as $post) : setup_postdata($post); $count++; ?><div> <img src="<?=wp_get_attachment_url(get_post_thumbnail_id());?>" alt="<?=the_title();?>" /> <h3><?=the_title();?></h3><h4><?=the_subtitle();?></h4></div> <?php endforeach; ?> </li> </ul> Code (markup): That's what I'm doing now and it's not working out to be a good long term solution. I would like to have a <ul> and have posts $count%4 and foreach posts be <div></div> and for each column <li></li> to be evenly set. Any help would be greatly appreciated!! Thanks!!
Do you always want a particular post to be in a specific column? If so you will have to record the column selection in the db. Otherwise why cant you just render them in different columns?
I shouldn't have to store column location within the database....... . I am trying to take all posts from a category and split them ( without css ) into 4 columns... I should be able to count posts and split count like count%4 and loop foreach or while but I can't seem to figure it out. Right now if posts are added to the category I have to go into the category area and change the number of posts and offsets.... Which I shouldn't have to.
$mydata = array( 1,2,3,4,5,6,7,8); $i=0; foreach($mydata as $data){ if($i==4){ $i = 0; } $columns[$i][] = $data; $i++; }