From dec5c61928d3e3811b8eb5162368c9086e8ea9a1 Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Tue, 14 Aug 2012 10:49:27 +0400 Subject: [PATCH 1/2] No need for the_post and rewind_posts in author archives. We can get all the information we need about the author by using get_queried_object within is_author. --- archive.php | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/archive.php b/archive.php index dc79c492..03bbd8c9 100644 --- a/archive.php +++ b/archive.php @@ -25,16 +25,9 @@ get_header(); ?> printf( __( 'Tag Archives: %s', '_s' ), '' . single_tag_title( '', false ) . '' ); } elseif ( is_author() ) { - /* Queue the first post, that way we know - * what author we're dealing with (if that is the case). - */ - the_post(); - printf( __( 'Author Archives: %s', '_s' ), '' . get_the_author() . '' ); - /* Since we called the_post() above, we need to - * rewind the loop back to the beginning that way - * we can run the loop properly, in full. - */ - rewind_posts(); + // Get the queried author data. + $author = get_queried_object()->data; + printf( __( 'Author Archives: %s', '_s' ), '' . esc_html( $author->display_name ) . '' ); } elseif ( is_day() ) { printf( __( 'Daily Archives: %s', '_s' ), '' . get_the_date() . '' ); From 103ae2cdf6150e2d6f660eb101ff968666e40a87 Mon Sep 17 00:00:00 2001 From: Konstantin Kovshenin Date: Mon, 27 Aug 2012 10:56:36 +0400 Subject: [PATCH 2/2] Correct use of get_queried_object() for author archives. The ->data object (used previously) stores the author data, but the WP_User class has the __get magic method that grants access to that data, so using get_queried_object() without ->data is correct, and compatible with 3.2, which does not use magic methods. Also url-escapes get_author_posts_url. --- archive.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/archive.php b/archive.php index 03bbd8c9..c9e57b13 100644 --- a/archive.php +++ b/archive.php @@ -26,8 +26,8 @@ get_header(); ?> } elseif ( is_author() ) { // Get the queried author data. - $author = get_queried_object()->data; - printf( __( 'Author Archives: %s', '_s' ), '' . esc_html( $author->display_name ) . '' ); + $author = get_queried_object(); + printf( __( 'Author Archives: %s', '_s' ), '' . esc_html( $author->display_name ) . '' ); } elseif ( is_day() ) { printf( __( 'Daily Archives: %s', '_s' ), '' . get_the_date() . '' );