WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Possible pagination question (10 posts)

  1. amanojaku2
    Member
    Posted 1 year ago #

    Hi everyone,

    I'm using a child of twenty eleven. I have a custom post type called 'trainer_profile'. It includes, as you may guess, information about personal trainers

    I have a menu item called 'Personal Trainers' When selected, it goes to a page-trainer-profile which contains a query that returns the title and permalink to each individual 'trainer_profile'.

    My question is about what to do when the number of profiles exceeds the 'posts per page' figure. Currently I have no idea. Using 'next_posts_link' etc I can create next and previous arrows, but they go to archive.php.

    What I want to do is redisplay page-trainer-profile's styling, with the next 10 profile permalinks displayed.

    I could use php or javascript to create a variable and use that to select what content to display, but I would image wordpress already has some functions that will do the same thing.

    Can anyone advise me on this?

    Thanks.

  2. Peter_L
    Member
    Posted 1 year ago #

    WP should be able to do this. Probably has something to do with your query. Could you show the template files, responsible for displaying the custom post type?

  3. amanojaku2
    Member
    Posted 1 year ago #

    The query is fairly simple:

    $wp_query = new WP_Query(array( 'post_type' => array('trainer_profile')));

    From that there is a bunch of html to display the title and permalink. (I can post it if you like, but I don't think it is relevant as it is only styling info based on while (have_posts()):the_post; ).

    If I add post_per_page =>10and the nav buttons, only 10 title permalinks display, then the 'next' arrow that takes me to archive.php.

  4. Peter_L
    Member
    Posted 1 year ago #

    Is posts_per_page, post_per_page or is that just a typo you made here?

  5. amanojaku2
    Member
    Posted 1 year ago #

    Yep, sorry about that!

  6. Peter_L
    Member
    Posted 1 year ago #

    What template file is this code on?

  7. amanojaku2
    Member
    Posted 1 year ago #

    page-trainer-profile

  8. Peter_L
    Member
    Posted 1 year ago #

    Pagination always confuses me but

    There is a section on WP_Query pagination parameters
    http://codex.wordpress.org/Class_Reference/WP_Query#Pagination_Parameters
    that mentions a page template and says you need to use an extra parameter in your query:

    $paged = (get_query_var('paged')) ? get_query_var('paged') : 1;
    $query = new WP_Query( array( 'paged' => $paged ) );

    That might be it but I'm not sure at all.

  9. amanojaku2
    Member
    Posted 1 year ago #

    I've been struggling to understand it myself, but thanks for the help! I think the answer is in there somewhere -as it stands, the 'next page' link goes still goes to the archive. The more I think about it, the easier it seems just to reload the same page, but pass a variable to it based on whether 'next' or 'previous' is clicked.

  10. amanojaku2
    Member
    Posted 1 year ago #

    For anyone reading:

    My problem was resolved with 2 key things- the first as Peter L describes above: using the $paged variable in the loop.

    The second is making sure you page and the cpt have different names. By changing the name of the page (and it's php file), the problem was resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic