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
https://forums.phpfreaks.com/topic/274793-php-grid-for-recent-posts/
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; ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.