WordPress.org

Ready to get started?Download WordPress

Forums

Sidebar Pagination works on Pages but not Posts (7 posts)

  1. endocreative
    Member
    Posted 2 years ago #

    I created a sidebar widget that displays authors on a website. The authors are added using a custom post type. It shows 10 per page, with pagination at the bottom to load the next 10 using AJAX.

    The plugin works fine on the homepage and pages, but doesn't work on posts. I've tried to spot the difference between single.php and page.php that would cause this to happen, but I can't find anything.

    Here is the code I'm using for the custom loop in the plugin:
    http://pastebin.com/iWwJn6Ac

    You can view the plugin in action here: http://timigustafson.com

    Is there another difference between pages and posts that I'm missing that could cause this to happen?

  2. mrwweb
    Member
    Posted 2 years ago #

    Howdy! Not all of this stuff is what I'm great at, but I can at least poke a prod a bit in hopes of bringing something to light.

    Can you describe how it doesn't work? Does it not display at all or does paging not work right or something else?

    A couple ideas/questions to kick things off:

    • I'm a little confused by the cat => -0. Is there even a category with the ID 0? Uncategorized is 1. I think cat=> -0 means show all posts NOT in cat 0. Is that what you're intending?
    • Regarding pagination, I believe you should be using get_query_var('page') instead of get_query_var('paged') (no "d" in "page"). (See: End of Pagination Section on WP_Query codex page.)
    • I'm not that familiar with wp_pagenavi() and pagination drives me crazy but do you even need the paged var in your wp_query call at all if you're using wp_pagenavi()?

    Finally, if you decide you do need the 'paged' argument, I think you'd want to do it this way (see: this):

    $paged = (get_query_var('page')) ? get_query_var('page') : 1;
    $my_query = new WP_Query( array( 'cat' => -0, 'post_type' => 'endo_contribute', 'posts_per_page' => 10, 'orderby' => 'meta_value', 'order' => 'ASC', 'meta_key' => 'endo_contributor_last_name', 'paged' => $paged ) );

    Hopefully that gives you a couple places to look. Let me know if you can rule any of this stuff out or in and we can keep digging.

  3. endocreative
    Member
    Posted 2 years ago #

    Thanks for your help Mark!

    Here's how it doesn't work:
    When the sidebar is loaded on posts, the pagination for the Guest Contributors won't go past the first page.

    Permalink on pages (works): http://timigustafson.com/health-club-radio/page/2/
    Permalink on posts (doesn't work): http://timigustafson.com/2010/never-too-soon-never-too-late/page/2/

    • I'm not sure what the cat => -0 was for. I probably found it on one of the code examples I've seen. I've removed it and it hasn't affected the functionality.
    • The pagination only works when using get_query_var('paged'). I've tried it both ways.
    • I tried removing the paged var but it broke the pagination.
    • I've updated the 'paged' arguement with your suggestion, but it didn't fix the original problem.

    I'm thinking it might be a permalink issue more than a loop issue since it works on pages and not posts. Maybe the date in the permalink on posts is messing something up?

  4. mrwweb
    Member
    Posted 2 years ago #

    That's a good thought re:permalinks. Have you tried disabling pretty permalinks and seeing if that fixes the problem?

  5. endocreative
    Member
    Posted 2 years ago #

    Based off this article on the Codex under the heading "Page Navigation Doesn't Work", I tried deleting and recreating the .htaccess file.

    However, despite numerous flushes, the pagination still doesn't work on posts.

    If I disable pretty permalinks altogether, will it mess up the site's URLs? Or can change them back after testing without affecting the URLs long term?

  6. mrwweb
    Member
    Posted 2 years ago #

    I've never had trouble with turning off pretty permalinks. When you flip them back on, they should go right back to the way they were before.

    Does wp_pagenavi have it's own support forums? I wonder whether you could find other people there with the same problem.

  7. endocreative
    Member
    Posted 2 years ago #

    I disabled pretty permalinks and got the plugin's pagination to work on both pages and posts. At least now I know its a permalink issue.

    Next step is figuring out how to change the permalinks in such a way that it doesn't affect site links and create 404 errors.

Topic Closed

This topic has been closed to new replies.

About this Topic