korak89 Posted February 21, 2013 Share Posted February 21, 2013 Hey everyone! So I have this code for wordpress that takes the featured image of a all the posts and displays the image and post title on one page. Then said image and post title links to that specific post. I'm very happy with how it functions right now, the only thing that I don't like right now is that it stacks above one another and I would like it to display in rows. Here is an example of it right now: http://blog-kora.marathonwebsites.com/ and here is my code: <?php global $post; $myposts = get_posts (); foreach( $myposts as $post ) : setup_postdata($post); ?> <h3><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></h3> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('feat_image');?></a> <?php endforeach; ?> could anyone add code to my (preferably) php to help add columns? I really need help with it and I have no clue what to do Quote Link to comment https://forums.phpfreaks.com/topic/274793-php-grid-for-recent-posts/ Share on other sites More sharing options...
korak89 Posted February 21, 2013 Author Share Posted February 21, 2013 for others trying, I found a code that did work beautifully .floatleft { float:left; height: 200px; width: 200px; margin:5px; background-color: #00CC99; } .floatclearer { clear:left; } <?php global $post; $myposts = get_posts (); $counter = 0; foreach( $myposts as $post ) : setup_postdata($post); if ($counter == $column) { $counter = 0; $otherclass = " floatclearer"; } else { $otherclass =''; } ?> <div class="floatleft <?php echo $otherclass;?> " id="post-<?php the_ID(); ?>"> <span class="title"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a></span> <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_post_thumbnail('feat_image'); ?></a> </div> <?php $counter ++; endforeach; ?> Quote Link to comment https://forums.phpfreaks.com/topic/274793-php-grid-for-recent-posts/#findComment-1414023 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.