Ready to get started?Download WordPress


[resolved] Two unordered lists to display 10 recent posts. (3 posts)

  1. reidorants
    Posted 2 years ago #


    I am looking for a way that I can display 10 (maybe 14) recent posts but split across two unordered lists, 5 (or 7) in each. I am looking to do this because I want them to display in two blocks next to each other. I will try and illustrate below:

    Post 10       Post 5
    Post 9         Post 4
    Post 8         Post 3
    Post 7         Post 2
    Post 6         Post 1

    Anyone know of a way I can do this?



  2. vtxyzzy
    Posted 2 years ago #

    Here is some sample code that should help:

    $posts_left_col = ceil($wp_query->post_count / 2);
    $posts_count = 0;
    <?php if (have_posts()) : ?>
       <ul class="two-column">
       <?php while (have_posts()) :
          the_post(); ?>
          <li><?php the_title(); ?></li>
          <?php if (++$posts_count == $posts_left_col) { ?>
             </ul><ul class="two-column">
          <?php }
       endwhile; ?>
       <div style="clear: both;"></div>
    <?php endif; ?>

    And here is the style:

    <style type="text/css">
    ul.two-column {
       width: 45%;
       float: left;

    You might need to adjust the width, depending on your margins and padding.

  3. reidorants
    Posted 2 years ago #

    Thank you so much! Worked perfectly :D

Topic Closed

This topic has been closed to new replies.

About this Topic