Title: Simple multi loop question
Last modified: August 20, 2016

---

# Simple multi loop question

 *  Resolved [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/)
 * I recently started experimenting with loops. This seems easy to achieve, but 
   none of the solutions in the WP codex or in my various google searches have helped.
   This is what I’m trying to get:
 * Page 1
    Column A – Loop X – first post Column B – Loop Y – second post Page 2
   Column A – Loop X – third post Column B – Loop Y – fourth post
 * etc.

Viewing 13 replies - 1 through 13 (of 13 total)

 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769376)
 * This is not simple. In particular, the page navigation would need to depend on
   the loop with the most posts, so the standard ‘next/previous_posts_link()’ functions
   will not work.
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769377)
 * Hm, maybe I should stick to one loop then.
 * However, I was running into issues separating the posts into columns with a single
   loop.
 * Column A would be fine, but Column B was treated as the first child column, since
   it was in the loop. Therefor it didn’t have a left margin.
 * I couldn’t think of a way to dynamically insert that margin in between the two
   columns other than to code the layout first and then fill it in with the loops.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769383)
 * Here is an article with some **_sample_** code to show how to put posts in columns.
 * The code is meant only as a guide, not to be used ‘as is’.
 * [http://wordpress.mcdspot.com/2010/11/28/align-posts-in-a-row/](http://wordpress.mcdspot.com/2010/11/28/align-posts-in-a-row/)
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769402)
 * Awesome, thanks! After about an hour of fiddling around with it, I’ve achieved
   half of the functionality I’m after. Now, my only two issues are:
 * 1. it displays posts from all categories (tried adding in a separate query to
   display category ’11’ but it turned up blank)
    2. pagination breaks after a few
   pages (fiddling around with reading post count and my category post counts set
   via functions.php seems to have some effect, but it still breaks)
 * Any suggestions? I used the code pretty much as is, but changed the CSS, post
   data section, and posts per row/page. The general structure is still the same.
 * edit: Also, any way to implement this code via echo?
    onclick=”location.href='
   <?php the_permalink() ?>’;” Previously I had been using this easy solution (the
   others didn’t work) to make the entire div a link. However, the apostrophes around
   the php seem to be conflicting with the inherent echo’code’ markup.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769413)
 * > 1. it displays posts from all categories (tried adding in a separate query 
   > to display category ’11’ but it turned up blank)
 * To display a single category, all you need to do is add the ‘cat’ argument to
   the $args array:
 *     ```
       $args = array(
          'posts_per_page' => $posts_per_page,
          'paged' => $paged,
          'cat' => 11,
       );
       ```
   
 * > 2. pagination breaks after a few pages (fiddling around with reading post count
   > and my category post counts set via functions.php seems to have some effect,
   > but it still breaks)
 * Just saying ‘pagination breaks’ is not much help. Pagination problems are notoriously
   difficult to find without access to the site so some debugging can be done. It
   might help if you put the full code of the template in a [pastebin](http://pastebin.com)
   where I can see it.
 * > Also, any way to implement this code via echo?
 * I would need to see the entire echo statement to tell anything about this.
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769419)
 * Can’t tell you how much I appreciate your helping me. I’m still new to wordpress
   and coding, and I try to solve everything on my own (usually by trial or error)
   but I definitely bit off more than I can chew with this endeavor.
 * [Here](http://pastebin.com/30AXea1n) is the code for my loop template. Please
   let me know if you need anything else. I considered emailing you instead, but
   maybe some other member will benefit from this as well. I plan on spending the
   weekend educating myself on your site 😉
 * edit: also, please ignore the breaks, internal hr styling, etc. (embarrassing!),
   my work is very sloppy until I finalize everything
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769421)
 * I don’t see anything wrong with the code. Some time ago there was a bug in pagination
   in categories. I thought it was fixed, but try installing the plugin that fixed
   that error:
 * [http://wordpress.org/extend/plugins/category-pagination-fix/](http://wordpress.org/extend/plugins/category-pagination-fix/)
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769422)
 * Figured out the error was from not previously not having specified the category.
   Its working perfectly now!
 * Which leaves my final issue, adding the onclick url function to the post_class
   div. Without the echo, I’d do:
 * <div class=”post_class” onclick=”location.href='<?php the_permalink() ?>’;”>
 * but the echo seems almost incompatible with the function, I’m guessing due to
   the conflicting apostrophes or quotes?
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769424)
 * I have not tested this, but I think it is OK:
 *     ```
       echo "<div class='post_class' style='' onclick=\"location.href='>"; the_permalink(); echo "'\"";  // Start one post
       ```
   
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769426)
 * So close! Issues:
 * 1. messes up styling, subsequent divs are not recognized
    I noticed the original
   code had a >\n” at the end, does that close off the echo to initiate the div?
   I tried inserting it in various places to no avail.
 * 2. only works for the first page
    links on the second page direct to /category/
   page/2/>http:/host.org/2012/2149/
 * Let me know if seeing the site itself would help.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769429)
 * Of course it would help.
 *  [vtxyzzy](https://wordpress.org/support/users/vtxyzzy/)
 * (@vtxyzzy)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769430)
 * I think I left out a closing >. Please try this:
 *     ```
       echo "<div class='post_class' style='' onclick=\"location.href='>"; the_permalink(); echo "'\" >";  // Start one post
       ```
   
 *  Thread Starter [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * (@atakajeff)
 * [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769431)
 * emailed you the link
    issue #1 solved, still left with #2

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Simple multi loop question’ is closed to new replies.

## Tags

 * [columns](https://wordpress.org/support/topic-tag/columns/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 13 replies
 * 2 participants
 * Last reply from: [atakajeff](https://wordpress.org/support/users/atakajeff/)
 * Last activity: [14 years ago](https://wordpress.org/support/topic/simple-multi-loop-question/#post-2769431)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
