Support » Fixing WordPress » Help Needed: Show posts in different divs? Screenshots included!

Viewing 3 replies - 1 through 3 (of 3 total)
  • How about something like:

    <?php $left_right = 'left'; ?>
       <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
         <div class="offer-<?php echo $left_right; ?>">
          <!--Your post content -->
          <?php $left_right = ('left'==$left_right) ? 'right' : 'left'; ?>
         </div>
       <?php endwhile; else: ?>
         <p>Sorry, no posts we're found.</p>
       <?php endif; ?>

    You will of course need to write the css for the classes offer-left and offer-right but this should alternately put posts in left column and right column…

    Hope that helps

    Emile

    http://acroweb.co.uk

    Thanks for the quick reply. I’ve already created the necessary divs with the correct styling so in your above example would it be as simple as replacing ‘offer-left’ and ‘offer-right’ with my equivalents?

    It should be –

    Code is quite simple – is sets up a variable ($left_right) and each time wordpress goes through the loop, the value of the variable is changed between “left” and “right”.

    This value is then appended to offer- to make two classes, offer-left and offer-right (alternately)…

    I hope that makes sense.

    Emile

    http://acroweb.co.uk

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Help Needed: Show posts in different divs? Screenshots included!’ is closed to new replies.