2

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?

2 Answers 2

3

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

3
  • 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, 2010 at 22:55
  • Happy to help.. :)
    – t31os
    Dec 18, 2010 at 10:53
  • 1
    Just wanted to report back that it works beautifully.
    – Davy8
    Jan 12, 2011 at 18:16
0

Seems like this could be done with Custom Queries.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.