Support » Fixing WordPress » Spread posts from same query evenly in 3 divs/columns

  • Hi i try to get something like this:

    <div id="awards">
        <div class="third">
            Post 1
            Post 4
            Post 7
            .....
        </div>
        <div class="third">
            Post 2
            Post 5
            Post 8
            .....
        </div>
        <div class="third">
            Post 3
            Post 6
            Post 9
            .....
        </div>
    </div>

    At the moment i have only 24 posts and im doing 3 query`s. Second query is with 8 offset and third query is with 17 offset. This is bad solution as now all future posts will only go to third column. I want to spread it evenly.

    This is my code now:

    <div id="awards">
                <div class="third">
                    <?php
                    $args = array(
                        'post_type' => 'awards',
                        'posts_per_page' => 8,
                        'order' => ASC
                    );
                    query_posts($args);
                    while (have_posts()): the_post(); ?>
                        <div class="copy">
                            <h2><?php the_title(); ?></h2>
                            <?php the_content(); ?>
                        </div>
                    <?php endwhile; ?>
                </div>
                <div class="third">
                    <?php
                    $args = array(
                        'post_type' => 'awards',
                        'posts_per_page' => 9,
                        'offset' => 8,
                        'order' => ASC
                    );
                    query_posts($args);
                    while (have_posts()): the_post(); ?>
                        <div class="copy">
                            <h2><?php the_title(); ?></h2>
                            <?php the_content(); ?>
                        </div>
                    <?php endwhile; ?>
                </div>
                <div class="third">
                    <?php
                    $args = array(
                        'post_type' => 'awards',
                        'posts_per_page' => 8,
                        'offset' => 17,
                        'order' => ASC
                    );
                    query_posts($args);
                    while (have_posts()): the_post(); ?>
                        <div class="copy">
                            <h2><?php the_title(); ?></h2>
                            <?php the_content(); ?>
                        </div>
                    <?php endwhile; ?>
                </div>
            </div>

Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Spread posts from same query evenly in 3 divs/columns’ is closed to new replies.