Jump to content

php grid for recent posts


korak89

Recommended Posts

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 :(

Link to comment
Share on other sites

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; ?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.