WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Multiple Loops and Pagination in conflict on Single.php (20 posts)

  1. james smith
    Member
    Posted 5 years ago #

    Hi

    My blog is here. I have 2 loops on the page, Loop1 is the center. Loop2 is the right-hand sidebar. Loop1 is paginated, and shows a single post, using this code:

    <?php if (have_posts()) : ?>
    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('cat=19,20,&paged=$paged'); ?>
    <?php while (have_posts()) : the_post(); ?>

    When I click the Page Link I'm taken to the Single post page. There, the Loop2 produces errors. Loop2 is fine when you're on the first page: and then it screws up on pages 2 and 3: Page 2, Page 3

    I have this code in Loop1 on the Single page:

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts('cat=19,20,&paged=$paged'); ?>

    When I remove that code, Loop2 is screwed up on ALL the pages, not just pages 2 and 3.

    Does anyone have any ideas? Thanks in advance.

  2. SimonJ
    Member
    Posted 5 years ago #

    Hum... I don't know if I understand what you're trying to do...

    1- You have a index.php or a home.php with two loops :
    a) first loop in the center column to display one post with pagination.
    b) second loop in the right column to display some other posts

    2- Then, when you click on a permalink (the link to the post itself) in the center column, you're directed to single.php where you want :
    a) the post displayed in the center column
    b) and the same loop as above in the right column to display some other posts.

    Tell me if I'm right.

    S.

  3. james smith
    Member
    Posted 5 years ago #

    Yeah, you were right. I accidentally got it to work by trying every query I could google. Now the issue is that pagination is broken.

    The Center column is displaying posts like this:

    <?php if (have_posts()) : ?>
    
      <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1; query_posts($query_string.'showposts=1&cat=19,20&paged=$paged'); ?>  
    
           <?php while (have_posts()) : the_post(); ?>

    The Right column displays posts properly using any of these:

    <?php query_posts($query_string.'cat=-19,-20'); ?>
    <?php while (have_posts()) : the_post(); ?>

    or

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts($query_string.'cat=-19,-20&showposts=2&paged=$page'); ?>
    <?php while (have_posts()) : the_post(); ?>

    or

    <?php
    $thePage = $_GET["paged"];
    query_posts("cat=-19,-20&paged=$thePage");
    <?php while (have_posts()) : the_post(); ?>
    ?>

    But, regardless of which code I use, pagination on BOTH columns is subsequently broken.

    I've been thinking about using SimplePie to feed my rss into one column or the other. But then if you wanted to see old posts, I'd have to load the entire archive into that column, and that seems a little ridiculous to me. There's got to be a cleaner way.

    Any help is greatly appreciated.

  4. SimonJ
    Member
    Posted 5 years ago #

    Hum... You want pagination on both column???

    Well... For now, try this :

    CENTER COLUMN HOME.PHP

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("showposts=1&cat=19,20&paged=$page");
    ?>
    <?php while (have_posts()) : the_post(); ?>
    --- DO YOUR STUFF (title, hyperlink, date, author, content, etc.)---
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    RIGHT-HAND COLUMN HOME.PHP

    <?php query_posts($query_string.'cat=-19,-20'); ?>
    <?php while (have_posts()) : the_post(); ?>
    --- DO YOUR STUFF (title, hyperlink, date, author, content, etc.)---
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    And, of course, in single.php, in the center column, you use a standart loop, with no query_posts...

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    And in the right-hand column of your single.php, you still display the same loop you use in home.php...

    <?php query_posts($query_string.'cat=-19,-20'); ?>
    <?php while (have_posts()) : the_post(); ?>
    --- DO YOUR STUFF (title, hyperlink, date, author, content, etc.)---
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>

    S.

  5. SimonJ
    Member
    Posted 5 years ago #

    Oh!

    Just realize I made a mistake in the first loop above... I made the correction :

    CENTER COLUMN HOME.PHP

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("showposts=1&cat=19,20&paged=$page");
    ?>
    <?php while (have_posts()) : the_post(); ?>
    --- DO YOUR STUFF (title, hyperlink, date, author, content, etc.)---
    <?php endwhile; ?>
    <?php wp_reset_query(); ?>
  6. james smith
    Member
    Posted 5 years ago #

    It was a valiant effort, but no soap. I've decided to alter the design a little bit-- I'm not going to try and get pagination working on both columns. I won't hold it against you if you could help me get it working on the Right column though.

    This is what I've got working right now (the colors are just to see where everything is really located).

  7. SimonJ
    Member
    Posted 5 years ago #

    Just to tell you, you also have a lot of css issues...

    Look at your validation...

    Your pagination problem is probably not relative to these errors... But you rally not have three columns here. Your <body> tag seems to be misplaced, etc. In both i.e. and firefox, your grey right column appears under the left and center one. And in IE, your header appears like this :

    http://koolos.com/WP_DEV/share_img/jamesmith_blog.gif

    (these problem are here since the begining)

    ----------------------------

    To investigate deeper your problem, could you paste there :

    http://www.pastebin.ca/

    Your complete index.php, or home.php, where you are using these loop and the pagination. Then, give us the link to the complete code.

    S.

  8. SimonJ
    Member
    Posted 5 years ago #

    Oh... And I forgot... Do the same with your sidebar... Paste the code in the pastebin.ca...

    S.

  9. james smith
    Member
    Posted 5 years ago #

    Hey, thanks very much for that. Here are the links...

    index.php

    sidebar.php (left column)

    sidebar3.php (right column)

    styles.css

    I knew the css was screwy, but I'd been focusing on trying to get the thing functional before trying to make it look good. Weird thing is, the it looks fine for me in Firefox on Windows.

    Anyway, thanks again.

  10. SimonJ
    Member
    Posted 5 years ago #

    kewl kewl...

    Well..

    What is this code in the sidebar.php :

    <?php iinclude_page(11); ?>

    I know it comes from the include page plugin... It is this page wich contain the:

    <div class="ngg-galleryoverview" id="ngg-gallery-2">

    And the folowing... the slide show I see in your live html source... ?

    If yes, what do you have in this page/file ?

    S.

  11. james smith
    Member
    Posted 5 years ago #

    The code for iinclude_page is here.

    I haven't edited it at all. The page that's being included hasn't had anything added either, I just made it a pretty basic page. It starts with the standard query:

    <?php if (have_posts()) : ?>
    	<?php while (have_posts()) : the_post(); ?>
  12. SimonJ
    Member
    Posted 5 years ago #

    Hum...

    So where does the code for the slide show I see in your left side bar is coming from ?

    It start like this :
    <div class="ngg-galleryoverview" id="ngg-gallery-2">

    And it comes from the nggallery plugin...

    And what is the purpose to include page 11 in the sidebar ?

    -----------------------

    What I suspect is that the culprit is Nextgen Gallery... Or another code/plugin in the sidebar...

    Your next troubleshooting step would be to make a straight three column with the loops I gave you yesterday for the center column and the right-hand one...

    Keep your sidebar.php (the left column) and the header.php as straight as possible... No special code, no plugin... Also, disable the plugins...

    Get your pagination and loops to work before adding any extras...

    S.

  13. james smith
    Member
    Posted 5 years ago #

    Ah, okay. The sidebar does this: <?php iinclude_page(11); ?> . Page 11 is where I put the gallery originally, so I just used the iinclude_page to grab it. I was really just trying to see if I could.

    You're right about stripping out all the extras, but I should note that my problems started before putting the gallery in there.

    I was trying to update the template I already had in there, but I think you're right and I should just start from scratch. I guess Kubrick is the best place to start?

  14. SimonJ
    Member
    Posted 5 years ago #

    Kubrick is a hell to modify... :-)

    I really don't like the CSS structure...

    If you want to re-start from zero, you can take kubrick as an inspiration... And build your own...

    And in few hours, I will be done with my new project : The Simpliest WordPress Theme Ever... :-)) A sort of "base theme" to start with... I'll give you a buzz when it will be done...

    ---------------

    The problem is that the loops I gave you above should really work... I tested it in my test installation, you can see it in action there :

    http://www.koolos.com/WP_DEV/

    As you see, it's in french, but I have a list of posts on the right sidebar titled :---POSTS WITH QUERY_POSTS---

    And I have the same query_posts loop in the main column with the get_query_var('paged') and the pagination works...

    So the problem is not in these loops... It comes from elsewhere...

    S.

  15. SimonJ
    Member
    Posted 5 years ago #

    Oh... And also... You wrote :

    You're right about stripping out all the extras, but I should note that my problems started before putting the gallery in there.

    The problem is maybe not in this inclusion itself, but with a plugin... That's why I would recommend to de-activate any plugin while you are building your theme...

    S.

  16. james smith
    Member
    Posted 5 years ago #

    In the sidebar, could you have the actual posts running there too, or can you only list them? And could you have them open in the sidebar, while the main column remains static? That's what I was after, which may not even be possible. I don't think css likes me very much.

    My email is jamesmith3 at gmail dot com if you want to email me when your base theme is done.

  17. SimonJ
    Member
    Posted 5 years ago #

    Everything is possible...

    Of course, you can have the posts running in a right sidebar, with the content. Here, I just put the title and permalink...

    -------------------------------
    If you want, when you open a post permalink in the right sidebar, to get it open along with comments, etc, in this same right colun it is also possible... More tricky, put possible :

    I would do it with a conditionnal tag... For instance :

    Let say...

    1- You display posts from category "cat" in the main center column

    2- You display posts from category "dog" in the right sidebar column

    Then, with a conditional tag, you can choose how to display your single.php...

    1- If post are in category "cat", the loop and comment template will be in the main center column.

    2- If posts are in category "dog", you put the loop and the comment template in the right column...

    It's totally possible...

    I would also guess that it's even possible to do it with a custom field instead of a category... If posts have the custom field with a value "right", then we use the right sidebar template...
    ------------------------------

    S.

  18. james smith
    Member
    Posted 5 years ago #

    Simon,

    Okay, I downloaded the 3-column basic theme from here: http://www.refueled.net/blank-wordpress-themes and deactivated all my plugins.

    This is the code for my Main column: http://www.pastebin.ca/1304737

    I wasn't sure if I was supposed to put

    <?php if (have_posts()) : ?>

    before the query. When I don't include it, the page comes up blank (but somehow works when I use it in the original Kubrick). When I do include it, the query works.

    Then, I put the code you provided into the Right sidebar: http://www.pastebin.ca/1304741 and that breaks the sidebar-- it doesn't load at all.

    I stripped out as much of the code in the original template as possible that would still allow it to work, and still had the above problems. Any ideas? If you don't mind, could I see the code for your columns here?

  19. james smith
    Member
    Posted 5 years ago #

    There was an error in the Right sidebar. I corrected it, but had the same issues:

    http://www.pastebin.ca/1304815

  20. SimonJ
    Member
    Posted 5 years ago #

    I wasn't sure if I was supposed to put
    <?php if (have_posts()) : ?>

    You should put it after the query_posts :

    <?php
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
    query_posts("showposts=1&cat=19,20&paged=$page");
    ?>
    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    1 -> Go query these posts
    2 -> If there is some posts relative to this query
    3 -> Then, do the folowing while you display the posts...

    --------------

    Did you got it? I saw in your site that you have three columns and the posts are displayed. Did you manage to get it work ?

    S.

Topic Closed

This topic has been closed to new replies.

About this Topic