• Hello,

    Ok, so I’m working on a layout for my blog and wondering what the better way of doing it is. What I want is to have the most recent post larger on top and up to 6 older posts smaller and in two columns. This is what I have so far.

    <!-- you want to show 7 posts per page... -->
    <?php query_posts("showposts=7"); ?>
      <?php while (have_posts()) : the_post(); ?>
        <?php if ($post->ID == $posts[1]->ID || $post->ID == $posts[3]->ID || $post->ID == $posts[5]->ID) { ?>
        <!--row -->
        <div class="row">
      <?php } ?>
      <?php if ($post == $posts[0]) { ?>
        <!--toppost -->
        <div class="toppost" id="post-<?php the_ID(); ?>">
          <!-- Most recent post here -->
        </div>
        <!--/toppost -->
        <?php } elseif ($post == $posts[1] || $post == $posts[2]) { ?>
        <!--post -->
        <div class="<?php echo ($post == $posts[1]) ? "post left" : "post right"; ?>" id="post-<?php the_ID(); ?>">
          <!-- Older post goes here, either on left or right -->
        </div>
        <!--/post -->
        <?php } elseif ($post == $posts[3] || $post == $posts[4]) { ?>
        <div class="<?php echo ($post == $posts[4]) ? "post left" : "post right"; ?>" id="post-<?php the_ID(); ?>">
          <!-- Older post goes here, either on left or right -->
        </div>
        <!--/post -->
        <?php } elseif ($post == $posts[5] || $post == $posts[6]) { ?>
        <div class="<?php echo ($post == $posts[5]) ? "post left" : "post right"; ?>" id="post-<?php the_ID(); ?>">
          <!-- Older post goes here, either on left or right -->
        </div>
        <!--/post -->
      <?php } ?>
    
      <?php if ($post->ID == $posts[2]->ID || $post->ID == $posts[4]->ID || $post->ID == $posts[6]->ID) { ?>
        </div>
        <!--/row -->
      <?php } ?>
    
    <?php endwhile; ?>

    Any suggestions on doing this better? I know its quite hackish but it’s all I could figure out how to do what I wanted.

    Any tips/suggestions are appreciated.

Viewing 1 replies (of 1 total)
  • Thread Starter gviscardi

    (@gviscardi)

    Ok I found a more elegant solution that seems to work so far:

    <?php if (have_posts()) : ?>
      <!-- you want to show 7 posts per page... -->
      <?php
        $col = "left";
        query_posts("showposts=7");
        while (have_posts()) : the_post();
      ?>
    
      <?php if ($post == $posts[0]) { ?>
      <!--toppost -->
      <div class="toppost" id="post-<?php the_ID(); ?>">
        <!-- Most recent post here -->
      </div>
      <!--/toppost -->
    
      <?php continue; } else { ?>
        <?php if ($col == "left") { ?>
        <!--row -->
        <div class="row">
        <?php } ?>
        <!--post -->
        <div class="smallpost <?php echo $col; ?>" id="post-<?php the_ID(); ?>">
          <!-- Older post goes here, either on left or right -->
        </div>
        <!--/post -->
        <?php } ?>
    
        <?php if ($col == "right") { ?>
        </div>
        <!--/row -->
        <?php } $col = ($col == "left") ? "right" : "left"; ?>
    
      <?php endwhile; ?>

    It seems to be very dynamic and elegant, and works well so far.

Viewing 1 replies (of 1 total)
  • The topic ‘Most recent post larger in center, older posts smaller and on left and right’ is closed to new replies.