1

I have the following so far:

<?php $count = 0; while (have_posts()) : the_post(); $count++; ?>

                <?php if ($count < 5) : ?>
                    //four posts here, all them wrapped in one div, these will also have different markup
                    <?php the_title();?>



                <?php else : ?>
                   //remaining six posts here, all of them wrapped in one div, these will also have different markup
                    <?php the_title();?> blah
                    <?php the_excerpt();?>

                <?php endif; ?>


            <?php endwhile; ?>

I want to wrap the first 4 in a '<div class="top"></div>' and the bottom 6, I want all of them wrapped in a '<div class="bottom"></div>'

Any tips of how this can be done using the while loop would be greatly appreciated

2 Answers 2

1

Try the below snippet.

<?php 
$count = 0;

while (have_posts()) : the_post(); $count++; 

    if ( $count == 1 ) echo '<div class="top">';
    if ( $count > 5 ) echo '</div><div class="bottom">';

    the_title();
    if ( $count > 5 ) the_excerpt();

endwhile;

echo "</div>"
?>
Sign up to request clarification or add additional context in comments.

3 Comments

I think you need to change the_excerpt(); line to if ($count > 5) the_excerpt(); as the OP only wants the excerpt to appear in the second DIV
@Venkatraman, what I want to add html in those different loops, this doesn't allow for that huh?
if you want few more html in each condition you can follow <?php if ($count > 5) : ?> your html <?php endif; ?>
0

This might help you.

        <?php $count = 0; while (have_posts()) : the_post(); $count++; ?>

            <?php if ($count < 5) : ?>
                //four posts here, all them wrapped in one div, these will also have different markup
               <div class="top">
                <?php the_title();?>
               </div>



            <?php else : ?>
               //remaining six posts here, all of them wrapped in one div, these will also have different markup
                <div class="bottom">
                <?php the_title();?> blah
                <?php the_excerpt();?>
                </div>
            <?php endif; ?>


        <?php endwhile; ?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.