WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Simple multi loop question (14 posts)

  1. atakajeff
    Member
    Posted 1 year ago #

    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.

  2. vtxyzzy
    Member
    Posted 1 year ago #

    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.

  3. atakajeff
    Member
    Posted 1 year ago #

    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.

  4. vtxyzzy
    Member
    Posted 1 year ago #

    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/

  5. atakajeff
    Member
    Posted 1 year ago #

    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.

  6. vtxyzzy
    Member
    Posted 1 year ago #

    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 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.

  7. atakajeff
    Member
    Posted 1 year ago #

    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 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

  8. vtxyzzy
    Member
    Posted 1 year ago #

    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/

  9. atakajeff
    Member
    Posted 1 year ago #

    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?

  10. vtxyzzy
    Member
    Posted 1 year ago #

    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
  11. atakajeff
    Member
    Posted 1 year ago #

    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.

  12. vtxyzzy
    Member
    Posted 1 year ago #

    Of course it would help.

  13. vtxyzzy
    Member
    Posted 1 year ago #

    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
  14. atakajeff
    Member
    Posted 1 year ago #

    emailed you the link
    issue #1 solved, still left with #2

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags