I'm working on a project where each category should have a custom header page. Any suggestions? I'm just looking for some direction on how to accomplish this.
3 Answers
Use the is_category()
condtional statement
if(is_category('category-a-slug')){
get_header('a');
}elseif(is_category('category-b-slug')){
get_header('b');
}
Install the plugin Taxonomy Images. In your header.php
check if you are in a category archive and if an image exists for that category. Then use that instead of the default image.
-
I hv 5 category and 5 header.php..each category should hv a different header...i.e. category A with header_a.php Category B with header_b.php any suggestion... Commented Jun 13, 2012 at 13:15
You can use custom templates for different categories. When displaying a category archive, WordPress will check for these files in order:
category-{slug}.php
category-{id}.php
category.php
archive.php
index.php
Read more at the WordPress Codex
If you prefer to use the one category.php
template, we can load custom header.php
files based on the category's ID. Replace the call to get_header()
in category.php
with the following code:
global $wp_query;
get_header( 'category-' . get_query_var('cat') );
WordPress will then look for header-category-{category_id}.php
and load that file if found. Otherwise, header.php
will be loaded as normal.