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 want to list 10 last posts of author in author.php template. I used this code:

<?php while (have_posts()) : the_post(); ?>
    <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>

But I can see only the last post of current author. Any help?

share|improve this question
    
Before that while, there's some QUERY... that's the important part. Please, edit your Question and add this information to it. –  brasofilo Nov 1 '12 at 2:32

2 Answers 2

up vote -1 down vote accepted

The easiest way would be to simply add:

global $query_string;
query_posts( $query_string . '&posts_per_page=-1' );

just before your code so you get :

<?php
global $query_string;
query_posts( $query_string . '&posts_per_page=-1' );
while (have_posts()) : the_post(); ?>
     <li><a href="<?php the_permalink() ?>"><?php the_title(); ?></a></li>
<?php endwhile;?>
share|improve this answer
    
Thanks man! :)) –  WHiSPER Nov 1 '12 at 5:39
3  
=o query_posts ! –  Tom J Nowell Nov 1 '12 at 12:09
    
@TomJNowell I know and that's way i started my answer with the easiest way ! The preferred way is hooking into pre_get_posts –  Bainternet Nov 1 '12 at 13:02
    
Fair dos, your answer does work afterall =] –  Tom J Nowell Nov 1 '12 at 23:46

Rather than clutter your author template, invoke a second query, and use query_posts ( avoid query_posts ), instead use this filter on pre_get_posts instead:

function wpse_show_all_authors($query){
    // if it's an author query
    if($query->is_author()){
        // put all the posts on page 1
        $query->set('posts_per_page',-1);
    }
    return $query;
}
add_filter('pre_get_posts','wpse_show_all_authors');

Put it in functions.php and it will work its magic on any and all author templates you have, without needing to modify author.php or execute 2 DB queries instead of 1.

share|improve this answer
    
Side note: this will add a check on every page load. not like the query_post method which will only effect author archives. –  Bainternet Nov 2 '12 at 19:30
    
I consider an if statement opcode to be orders of magnitude faster than a second DB query and thus worth the cost of a handful of instructions for a simple value comparison, a cost that can be eliminated trivially in even the most elegant of codebases, and that's done by WP Core itself many, many times already. –  Tom J Nowell Nov 3 '12 at 1:11

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.