Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Right, so what I currently have is a page split into three using a css grid. The third column is the sidebar, The first two each have a query for posts to display, and create a nice grid of posts (dummy content):

Each loop looks like this:

    <?php query_posts('showposts=5'); ?>
<?php $posts = get_posts('numberposts=5&offset=0'); foreach ($posts as $post) : start_wp(); ?>
<?php static $count1 = 0; if ($count1 == "5") { break; } else { ?>
-----Content -----
<?php $count1++; } ?>
<?php endforeach; ?>

This shows five posts in the first column, and the second loop displays five posts after (offset=5) the first five in the second column, totaling ten on the page and read top-bottom left-right. Naturally, this creates a problem with pagination.

What I would like to do is have the posts listed from left to right (but retain the fluid look it currently has with different sized posts) across both columns, or a tleast appear to (I can merge the columns into a two third/one third split), and when reaching the bottom, load the next 10 or so posts automatically (ultimately infinite scroll, but pagination first).

I'm not a php'er, and to be honest I don't understand most of this code. I've built this with help from the wordpress codex and sites like this, but have come to a stop. Any copy-pastable or easy to understand advice/answers are much appreciated.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

There's no reason to use multiple loops to get this effect: The look you want comes from the jQuery Masonry script, which is included in recent versions of WordPress.

Your post list as you describe it is just the standard post index, so use a single standard loop -- that is, a WordPress loop, as described in the Codex: Don't use repeated instances of query_posts(), which will require far more queries and be less performant and more error-prone. Having a single loop will also make your pagination and (eventual) infinite scroll issues disappear.

To use Masonry in your theme, you'll need to enqueue the script correctly:

Masonry has a number of display options, and documentation for the script is at

There's a good introductory-level writeup on building a theme using Masonry on the front page here: and there are many themes out there that use it if you want to dig into their code for further examples. Note that while the tutorial does a great job of describing how to fit the pieces together, it was written before Masonry was included in the core WP package; you no longer have to download a copy of the script as she describes.

share|improve this answer
Thanks a lot and extremely helpful! –  Bbvoncrumb May 20 '13 at 14:40

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.