WordPress.org

Forums

Help Needed: Show posts in different divs? Screenshots included! (4 posts)

  1. paa1605
    Member
    Posted 4 years ago #

    Hey guys,

    Im trying to display posts from a certain category on a certain page. The only problem is that they are listed in pairs where both divs are different sizes so i cant use the standard loop. How do i display the posts so that they take this into account?

    here is my current template page code:
    http://yfrog.com/g1screenshot20101105at172p

    and here is the result of three posts:
    http://yfrog.com/6xscreenshot20101105at173p

    As you can see, at the moment the code is showing each post in both of the different divs.

    This is something very similar to what i want instead:
    http://yfrog.com/n9screenshot20101105at172p

    Any help would be much appreciated, thanks.

  2. emilekott
    Member
    Posted 4 years ago #

    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

  3. paa1605
    Member
    Posted 4 years ago #

    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?

  4. emilekott
    Member
    Posted 4 years ago #

    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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.