WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] page URLs for custom page template only working for pages 5 and 6 (?!?) (4 posts)

  1. van-knowmad
    Member
    Posted 2 years ago #

    I have Page with permalink "/latest" that pulls in recent blog posts, recent news items (a CTP) and recent events (another CTP).

    I am now trying to get paging working, just for the blog posts' list, on this Page.

    The Page's template file is using a custom WP_Query object, and passing in the page number it gets with get_query_var( 'page' ).

    Typing in good, old query strings makes the paging work:

    index.php?pagename=latest&page=2,
    index.php?pagename=latest&page=4,
    etc...

    But I want the link structure to match the rest of the site.

    I am already am adding several custom rewrite rules in my theme's functions.php, so I added this one to the top:
    latest/page/?([0-9]{1,})/?$' => 'index.php?pagename=latest&page=$matches[1]'

    (I tested that regex with an online tester and it gives the correct results for dozens of page numbers)

    Here's the weird behavior:

    /latest still works.
    /latest/page/5 works by showing what is page 5 of the blog list.
    /latest/page/6 also works, and so on through latest/page/15, when I run out of posts to page through.

    But /latest/page/2, /latest/page/3, and /latest/page/4 all default to the generic home (index.php) page.

    I would like to use this URL structure, since it matches the paged archives, and allows me to use previous_posts_link() and next_posts_link() in my template.

    My rewrite rule has the highest priority of all the rules in the WP_rewrite array. What could be causing it to fail for those 3 low page numbers?

  2. van-knowmad
    Member
    Posted 2 years ago #

    Need to add: After additional testing, (changed to showing page numbers that start with (

  3. van-knowmad
    Member
    Posted 2 years ago #

    Need to add: After additional testing (I changed the template to only show 1 post per page), page numbers that start with 2, 3, or 4, like:

    /latest/page/20
    /latest/page/30
    /latest/page/40
    /latest/page/200
    /latest/page/300
    /latest/page/400

    don't work either, but /latest/page/50 works !

    Curiouser and curiouser...

  4. van-knowmad
    Member
    Posted 2 years ago #

    It turns out that someone had used a script to add a bunch of redirects to the .htaccess file, including ones that redirected:

    /page/2?
    /page/3?
    /page/4?

    to the homepage.

    Once I got rid of those, pagination worked without even adding any custom WP rewrite rules.

Topic Closed

This topic has been closed to new replies.

About this Topic