I use something like this:
function generate_page_title() {
$o = '';
global $cat, $post, $wp_locale, $wp;
$error_message = 'Sorry, we could not find what you are looking for.';
if( is_singular() ) {
$o = $post->post_title;
}
elseif( is_category() ) {
$o = single_cat_title( '', false );
}
elseif( is_tag() ) {
$tag_name = single_cat_title( '', false );
$o = ( $tag_name ) ? 'Entries Tagged: "' . $tag_name . '"' : $error_message;
}
elseif( is_search() ) {
$o = 'Search Results';
}
elseif( is_author() ) {
$this_author = ( isset( $_GET['author_name'] ) ) ? get_userdatabylogin( $_GET['author_name'] ) : $curauth = get_userdata( intval( $author ) );
if( $this_author )
$o = 'Entries posted by: ' . $this_author->display_name;
else
$o = 'Author Archives';
}
elseif( is_day() ) {
$d = ( isset( $wp->query_vars['day'] ) ) ? $wp->query_vars['day'] : substr( $_GET['m'], 4, 2 );
$m = ( isset( $wp->query_vars['monthnum'] ) ) ? $wp->query_vars['monthnum'] : substr( $_GET['m'], -1, 2 );
$y = ( isset( $wp->query_vars['year'] ) ) ? $wp->query_vars['year'] : substr( $_GET['m'], 0, 4 );
$t = mktime( 0, 0, 0, $m, $d, $y );
$o = 'Entries posted on ' . date( 'l F jS, Y', $t );
}
elseif( is_month() ) {
$y = ( isset( $wp->query_vars['y'] ) ) ? $wp->query_vars['y'] : substr( $_GET['m'], 0, 4 );
$m = ( isset( $wp->query_vars['monthnum'] ) ) ? $wp->query_vars['monthnum'] : substr( $_GET['m'], -1, 2 );
$o = 'Entries posted in ' . $wp_locale->get_month( $m ) . ', ' . intval( $y );
}
elseif( is_year() ) {
$y = ( isset( $wp->query_vars['year'] ) ) ? $wp->query_vars['year'] : $_GET['m'];
$o = 'Entries posted in ' . intval( $y );
}
return $o;
}
If you paste this function in your theme’s functions.php file, you can then call <?php print generate_page_title(); ?>
Where ever you want your page title to be. This function should be used outside the loop.