• Working on my customized blog. Have searched the forum and the codex, pulled out my remaining hair and gave my first born but still can’t make it work. Hoping that somebody can help me back on track.

    When using the index.php to display sub-category results the paged navigation works fine, see example at sub-category listing.

    But when I use a Page template to display all items from all sub-categories, only the 1st page shows items (depending on the amount I set in the preferences). The code for the next item and/or next page seems to work fine because the URL will show /page/2 but it’s just displaying the items of the first page again. Example: design category

    I’ve tried posts_nav_link() and next_posts_link (you can see the 2 links at the bottom, above the footer.

    What I do not understand is why a Page template would ‘react’ so differently and why the remaining images don’t show. And I definitely have no clue on what I am doing wrong here – it seems that only the first images get read and the rest dropped into nirvana. I’ve even installed different plugins, thinking my code was not correct but they all showed the same result. Obviously there SHOULD be more items on more pages but the pages don’t truly get generated (?) and thus it remains sitting on the first page of the item listing… my guess.

    Thanks in advance for any pointer.

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hi

    This code is the miracle worker that resolves your issue. I discovered this in an old forum post about ten days ago. This must be the tenth time since then I’ve posted it – seems like a very common issue.

    This assumes you are using query_posts or similar to set up your page template. You have to change cat=1 to whatever category(s) you are including on your page.

    <?php $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
          query_posts("cat=1&paged=$paged"); ?>
    Thread Starter mStudios

    (@mstudios)

    Can’t give you my first born as I have already slaughtered him for this problem… but THANKS, that was EXACTLY what I needed.

    I tried reading up on the code, what it does exactly, but all my searches did not answer it fully.

    I do understand that the variable $paged gets used in the ‘query_posts’ function and also the function ‘get_query_var()’ I do understand in it’s basics; but my understanding ends pretty much there when it comes to the first line.

    If there is somebody who can elaborate, that would be great. But I won’t sweat it if not.

    Thanks again for your help!

    Hi

    I was just researching that paging. It is not well documented any place I can find. Apparently “paged” keeps track of what page in a paginated set of posts the loop is displaying. That first line of code tests to see what page is displaying. It appears that if its not included in the query that the query always starts anew on each page with page 1, even when you are clicking a next page button. That is because query_posts overrides the default WP query that would normally be in place on a page. I assume that when not using query_posts that the regular WP code takes care of the pagination details. But when we take matters into our own hands we have to know some of the details that WP does automatically otherwise. An issue is where does one learn them.

    Thread Starter mStudios

    (@mstudios)

    thanks, this helps! I’ll chew for a little while on this one ??

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Next Page does not display existing items using Page Template’ is closed to new replies.