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.

Ok so here's another story for my Custom Pagination on Custom Author's Page. What i want to happen there is display the Author's avatar, description, website, and some additional fields, and of course list his post and paginate it....

Here's the screenshot of my custom author page: http://i56.tinypic.com/2cosldy.png

As you can see, everything seems to be in order. Now, the problem is the pagination. I used the code by Kreisi (Pagination w/o using plugins). What i did is create a custom loop and call it to Kreisi's function

here's the code

    $uid = $curauth->ID;
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$authloop = new WP_Query("author=$uid&paged=$paged");
$ppp = 5; //set my custom number of post to appear

$args = array(
           'post_per_page' => $ppp,
           'author' => $uid,
           'paged' => $paged

 );

$authorposts = get_posts($args);


if ( count( $authorposts ) > 0 ) {              

        foreach ( $authorposts as $post ):  setup_postdata($post)            

        ?>
                <li>
                        <?php if ( has_post_thumbnail() ) : ?>
                                <img src="<?php echo bloginfo('template_url'); ?>/inc/scripts/timthumb.php?src=<?php echo catch_that_image(); ?>&w=40&h=40&zc=1&q=30" alt="<?php the_title(); ?>" class="authorpostimg"/>

                        <?php else :    ?>
                                <img src="<?php echo bloginfo('template_url'); ?>/inc/scripts/timthumb.php?src=<?php echo catch_that_image(); ?>&w=40&h=40&zc=1&q=100" alt="<?php the_title(); ?>" class="authorpostimg"/>
                        <?php endif; ?>

                        <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;  

        wnw_authpagination($authloop->max_num_pages);

} else {
        echo '<p>No articles by this user</p>';
}

Here's the scenario for further understanding

Supposed the blog has a total of 30 blog posts, and the author Ven Francis has 15. If you can see on my variable, i did set the post_per_page value to 5. And on Kreisi's function it has the range of 2. (please visit the link to his code to further figure it out) So what it has to happen is that, pagination should show 5 page-buttons

[c] [2] [3] [>] [>>]

where [c] is the current... [3] and [>>] is the last page(3rd page). But what is happening on my situation is that, when you hover the [>>] it shows /page/6 and i think it's getting the total number of posts of the blog.

And if you click on 3(3rd page). It will still show the 4,5 and [>>] and it should not. like below illustration

[<<] [<] [1] [2] [c] [4] [5] [>] [>>]

I hope you understand the scenario and the problem. Thanks again and God bless!

PS: kreisi's not doing a support for his brilliant code anymore, so i gotta do this on my own. an i need a little help from you guys. Thank you!

share|improve this question

2 Answers 2

Try my (free & open source) "Easy Pagination Deamon". It's pretty advanced and should work on author templates too. Just stick with the readme presented on the link and works for paginated posts & pages too. You can also integrate it in your theme folder and call it in your functions.php with something like include_once( 'pagination.class.php' ); and then call it in your tempalte with oxo_pagination( array( 'your arguments' ) );.

share|improve this answer

You are creating two extra loops here:

$authloop = new WP_Query("author=$uid&paged=$paged");

And:

$authorposts = get_posts( array(
    'post_per_page' => $ppp, // Shouldn't this be postS_per_page?
    'author' => $uid,
    'paged' => $paged
) );

You use the $authloop to get the total number of pages, but you don't specify the posts_per_page value so it will take a default value there, which may not be the same as the 5 you specify in the actual post loop you use.

Next to that, most of the times it is a bad idea to use a custom loop with pagination. The problem is that WordPress will always do a query for you (to set up the main loop), and it will take the paged parameter from the URL with it. Say you are on an author archive. The default posts_per_page is 10. This author has 40 posts. Your custom loop shows only 5 posts per page. If you now are at page 5, WordPress will query for posts 41-50 instead of 21-25 as you would do in your custom loop. WordPress will find no posts and load the 404.php template instead of your author.php template.

For this reason, it's best not to do a custom loop, but hook into the default loop via pre_get_posts or another hook.

share|improve this answer

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.