Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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.

share|improve this question
    
You have been flagged for possibly duplicate accounts wordpress.stackexchange.com/users/5443/ven wordpress.stackexchange.com/users/5475/ven Please consider registering on site (or using some OpenID to login) and asking moderators to merge extra accounts so it is more convenient both for you and community. :) TIA –  Rarst May 28 '11 at 19:59
add comment

1 Answer

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.

share|improve this answer
3  
And even more important: don't call get_posts() or query_posts() yourself in the template file. Modify the standard query that WordPress will do anyway, using the method VicePrez explained here or using the pre_get_posts action. –  Jan Fabry May 17 '11 at 15:26
1  
THANK YOU VERY MUCH @VicePrez –  Steffi Jan 3 '12 at 19:06
    
No problem @Steffi –  VicePrez Jan 4 '12 at 6:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.