WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Pagination within page templates? (5 posts)

  1. theronin
    Member
    Posted 4 years ago #

    I've setup a page template called 'News' which displays a list of the 5 most recent news entries and displays the_excerpt() allowing the user to click on the title to view the full article.

    Each news item is a Post in the category of "news" but they are output on a Page (as noted above).

    I've gone to add wp_link_pages() within the loop and after the_exerpt() but nothing displays. I've set the posts to display as 5 and I have 10 in the database. It shows the 5 most recent as it should be there just aren't any page links at the bottom to flick to the next page of entries.

    I know I'm running WordPress as more of a CMS so I was just wandering that wp_list_pages() was being affected by the fact that it displayed within a Page Template? Should this still work?

    Is there anything which could be preventing the pagination controls from showing?

  2. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    as described in this article, http://codex.wordpress.org/Template_Tags/wp_link_pages is used for linking pageinated parts in pages, not page templates.
    added within the loop as described by you, it wil allow the posts to be split into multiple parts by inserting '<!--nextpage-->' into the post content, in the html editor.

    however, you are probably looking for something like http://codex.wordpress.org/Template_Tags/posts_nav_link
    which would be included somewhere after the 'endwhile' of the loop.

    also check the use of the 'paged' parameter of 'query_posts'
    http://codex.wordpress.org/Function_Reference/query_posts#Pagination_Parameters

  3. theronin
    Member
    Posted 4 years ago #

    Thanks for setting me straight on the use of wp_link_pages and thanks for pointing out post_nav_link too. This looks like what I need and having placed it outside the loop for the page in question I can now see the link to "Next Page ยป". However, when I click on the link it refreshes the page but the same articles are shown rather than the previous 5 (I have 5 per page set).

    With regards to the 'paged' parameter of 'query_posts' I'm not sure if this will help at all. Because each page of my News section contains 5 Posts and these posts will grow over time I don't want to define the total number of pages otherwise I'd have to go into the code and change it after every 5 new posts. I need this to be dynamic.

    Any ideas why the post_nav_link isn't working?

  4. alchymyth
    The Sweeper & Moderator
    Posted 4 years ago #

    the codex is not very clear with this pagination topic;
    see if this article helps:
    http://stylizedweb.com/2008/08/13/query_posts-pagination-problem/

  5. theronin
    Member
    Posted 4 years ago #

    Bingo! You hit the nail right on the head with that link. That was the exact problem I've been having and the proposed solution works perfectly for me. Thanks for pointing that out, and yes, I agree with you and Stylized Web that the WordPress Codex really aren't very clear about the topic. I didn't realise that query_posts overrides nearly everything in the standard posts objects query, including the page offset.

    Thanks again, and I'll keep it in mind for next time.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags