Different Header image for each category

Posted in: Newsmag
Post count: 15

Hello!
I use the Newsmag Header Style 7.
Now I want to change the header image (full header logo) with each category. How can I do this?
Thanks for your help
Dirk

Post count: 6535

Hi

You need to add a set of conditions in header-style-7.php and load a different logo image for each category like here: http://screencast.com/t/RDofG5R4YL

<?php
if (is_category('cat1')){
    echo '<img src="url image 1">';
}
elseif (is_category('cat2')){
    echo '<img src="url image 2">';
}
else {
    locate_template('parts/header/logo.php', true);
}
?>

This code should load a different logo image for the category pages but only when header style 7 it’s used. If you change the header style you need to apply the customizations in the file corresponding with the header style used.

Let me know how it goes.
Thanks!

  • This reply was modified 10 years by Andrei L..
Post count: 15

Thanks Andrei, it works perfectly. Great help!

  • This reply was modified 10 years by Vilfredo.
Post count: 15

Dear Andrei,
unfortunately your hint only works if a visitor hits the category-button. The header changes with the category-overview.
But if a visitor comes from a link to my site, the regular header is shown, not the one of the category the post belongs to. Even though I changed permalinks to “mysite.com/%category%/%postname%”. The theme should recognize the category and choose the header accordingly. Any ideas?
/%category%/%postname%
Example: http://www.captain-gadget.de/funkstation/das-heimnetzwerk-per-powerline-erweitern
Thanks
Dirk

Post count: 6600

Hi,

This is a post page: http://www.captain-gadget.de/funkstation/das-heimnetzwerk-per-powerline-erweitern so this isn’t among the conditions set for the header image, what I mean is that the solution Andrei gave you refer’s just to the category pages not for post the are part of that category. So if you need this to work for post pages also you need to customize this further and check the category of each post using wp methods/functions like the ones I’ve pasted below:

https://codex.wordpress.org/Function_Reference/in_category
https://codex.wordpress.org/Function_Reference/has_category
https://codex.wordpress.org/Function_Reference/wp_get_post_categories

Hope this helps!

Thanks!

Viewing 5 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic.