views:

49

answers:

1

hi

i am trying to get wordpress posts, 3 at a time, this is the code i'm using:

            <?php while ( have_posts() ) : the_post() ?> 
<?php  if(get_post_meta($post->ID, 'feature', true) != true) {; ?>
         <div class="show_col">
  <?php   for ($i = 1; $i <= 3; $i++) { ?>

<div class="set">
<a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"> 
<img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/&lt;?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
</a>    
<?php the_content("<P class='more'> Read More &#187; </p>"); ?>

</div>
<?php };  ?>
</div>           

<?php  }; ?>
<?php endwhile; ?>  

i know this loop is echoing ONE post THREE times - but what i really want is this end result

 <div class="show_col">
      <div class="show_col"> post1  </div>
      <div class="show_col"> post2  </div>
      <div class="show_col"> post3  </div>
 </div>
<div class="show_col">
      <div class="show_col"> post4  </div>
      <div class="show_col"> post5  </div>
      <div class="show_col"> post6  </div>
 </div>
<!-- and so on -->

i am doing this as the height of each post varies - therefore i add something like .show_col{clear:both} so that the next three posts go under neath

i hope you could help

thanks

A: 

This is the code you need (i corrected some of your syntax):

<?php $i = 0; ?>
<?php while ( have_posts() ): the_post();?> 
    <?php  if(get_post_meta($post->ID, 'feature', true) != true): ?>
    <div class="show_col">

        <?php if(($i%3) == 0): ?>
            </div>
            <div class="show_col">
        <?php endif;?>

        <div class="set">
        <a href="<?php the_permalink(); ?>" title="<?php printf( __('Permalink to %s', 'your-theme'), the_title_attribute('echo=0') ); ?>" rel="bookmark"> 
        <img class="image" src="http://localhost/portpress/wp-content/themes/myTemp/portfolio/&lt;?php echo get_post_meta($post->ID, 'intro_thump', true); ?>.jpg" width="300px" alt="AUREL #<?php the_ID(); ?>" />
        </a>    
        <?php the_content("<P class='more'> Read More &#187; </p>"); ?>

        </div>

    </div>           

    <?php  endif; ?>
<?php $i++; ?>
<?php endwhile; ?> 

also you seem to add a semi collon after closing the function ( }; ), don't dot that, there is no need for it.

krike
This will not work well for `$i == 0` ==> It'll make an empty div. ( `0 % 3 == 0`).
Peter Ajtai
you then just need to initialize $i to 1. just a small change. So the first line should be <?php $i = 1; ?>
krike
@krike - your code work i just need to delete the </div>s at lines 6 and 15 as they seemed to be too much (but that maybe due to my other code. thanks all
aurel
also - Peter Ajtai - fantastic explanation - thanks a lot, your code works too
aurel
@aurel - you are welcome, don't forgot to mark one of the answers as answered. :)
krike