Adding Pagination on a Custom Author Page

i have created a custom author’s page that list the title of their posts. but the problem is i can’t get the pagination to work if it’s beyond the set post per page value. i have used get_posts() to it’s custom loop.

<?php 
                    $ppp = 5; //set my custom number of post to appear
                    $uid = $curauth->ID;
                    $args = array(
                                    'numberposts' => $ppp,
                                    'author' => $uid

                                );
                    $authorposts = get_posts($args);
                    //print_r($authorposts);
                    if ( count( $authorposts ) > 0 ) {               

                        foreach ( $authorposts as $post ):  setup_postdata($post)            ?>
                            <li>


                                <a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>" class="authorpostlink"><?php the_title(); ?></a>
                                <?php the_excerpt(); ?>
                            </li>
                    <?php endforeach;  ?>
                        <div class="post-nav">
                            <div class="previous"><?php previous_posts_link('&lsaquo; Previous Page') ?></div>
                            <div class="next"><?php next_posts_link('Next Page &rsaquo;') ?></div>
                        </div>
                    <?php
                    } else {
                        echo '<p>No articles by this user</p>';
                    }       
                    ?>

This should display 5 post with it’s title and it’s excerpt by the author,….but the rest of the author’s posts isn’t paginated what it paginates is the whole number of post on the blog.

Related posts

Leave a Reply

1 comment

  1. Put the following code in your functions.php file.

    function limit_posts_per_page() {
    if ( is_author() ) // you can limit other pages as well ( i.e. is_archive() ), if need be.
        return 5;
    }
    add_filter( 'pre_option_posts_per_page', 'limit_posts_per_page' );
    

    Make sure your using the author.php template, otherwise it wont work. Please have a look at twentyten’s author.php for best practices.