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.

The following url resolves to the category template: http://localhost/author/myusername/?category_name=somecategory

I have a category-somecategory.php template and just a generic author.php template. Is there any way to make such a url use the author.php template instead of the category-somecategory.php? If not how can I filter on both category and author and force it to use the author template?

share|improve this question
add comment

2 Answers 2

up vote 3 down vote accepted

You could change the template loaded by hooking onto template_include, checking if is_author and is_category are both set, then switch the template for inclusion to the author template instead.

Give this a shot..

add_filter( 'template_include', 'my_template_setter' );
function my_template_setter( $template ) {
    if( is_author() && is_category() && is_archive() )
        $template = get_author_template();
    return $template;
}

You can do any number of conditional checks here before modifying which template gets loaded.

WordPress has several template fetching functions available already, i've used one in the example, but here's a list for quick reference...

get_404_template()
get_search_template()
get_taxonomy_template()
get_front_page_template()
get_home_template()
get_attachment_template()
get_single_template()
get_page_template()
get_category_template()
get_tag_template()
get_author_template()
get_date_template()
get_archive_template() 

Hope that helps..

share|improve this answer
    
Haven't tried using it yet (priority of this requirement got pushed down) but it appears like it should work so I'll give the accept. –  Davy8 Dec 17 '10 at 22:55
    
Happy to help.. :) –  t31os Dec 18 '10 at 10:53
1  
Just wanted to report back that it works beautifully. –  Davy8 Jan 12 '11 at 18:16
add comment

Seems like this could be done with Custom Queries.

share|improve this answer
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.