• I have put my WordPress posts into my website. So far so good. My troubles start when I try to get the pagination to work. SO far nothing I have tried has worked. Here is my code, any suggestions?

    [72 lines of code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter mechman0712

    (@mechman0712)

    Okay, now the page numbers show up and they link to http://www.mysite.org/page/2/, but it still shows the same posts. I am not sure where it is supposed to be statementing the loop.

    [89 lines of code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Looks like you are mixing a loop for WP_Query with a ‘foreach’ loop, and did not set $paged before your WP_Query().

    Put this just before the WP_Query() line:

    <?php
    global $paged;
    $paged = (get_query_var('paged')) ? get_query_var('paged') : ((get_query_var('page')) ? get_query_var('page') : 1);
    ?>

    That should allow the pagination to work, but does not address the problem of mixing WP_Query() with foreach. You should be able to do away with the foreach related lines and the special pagination function and use the built-in WP function paginate_links().

    Thread Starter mechman0712

    (@mechman0712)

    Okay, here’s what I got. It is still not paginating correctly. Every page still shows the same information. Somehow, the loop is not getting the next set of instances.

    [Code moderated as per the Forum Rules. The maximum number of lines of code that you can post in these forums is ten lines. Please use the pastebin]

    Please don’t post more than 10 lines of code – use a pastebin and post a link to it here.

    Your query does not have any arguments:

    $new_query->query();

    It at least has to have the paged argument, and probably others:

    $new_query->query("paged=$paged");
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Pagination a foreach loop’ is closed to new replies.