A Different Header Image for Each Category in the twenty eleven WordPress theme, we often come across topics over on the WordPress.org forum which we think are generic enough to make a good Twenty Eleven Child Theme download, and this theme comes from such a post.
The topic starter is creating a travel blog where each county is a category, we can add a different header to posts and pages but not to a category, we thought of several ways we could do this, and settles on a simple solution.
As we can already add a header to a single post, we thought how can we utilize these images as category headers, after some consideration the following solution was developed.
As always we created a child theme that can be downloaded with all the code fully working, we only needed to transfer the header.php from the parent and add a few lines of code, and in the functions.php we created a small function to get the header images url.
We are not going to look at the code, the files in the download have comments in them, we have added a couple of images at the end of this post to show where to find the changes.
Here is a list of posts in our featured category, as we can see the oldest post is “Normal Post 1”.
We want the same image to be presented to our website visitors each time they visit, so we will add a featured image, which should be at least 1000px wide, or it will not show as a header.
That done lets visit the website and look at the default header that is show normally.
Now we go to our category page for the category called “Featured”, where we can see our category header, a nice simple solution, not to much code.
Here are the screenshots of the code, all of the code in the child themes functions.php, and the additional code in the header.php.
We do require your feedback to improve our themes and tutorials, please leave your comments good or bad.
Code disclaimer information
If this document contains programming examples, www.DigitalRaindrops.net grants you a nonexclusive copyright license to use all programming code from which you can generate similar functions tailored to your own specific needs.
All sample code is provided by http://DigitalRaindrops.net for learning illustrative purposes only.
These examples have not been thoroughly tested under all conditions. www.DigitalRaindrops.net, therefore, cannot guarantee or imply reliability, serviceability, or function of these examples.
All programs contained herein are provided to you “AS IS” without any warranties of any kind. The implied warranties of non-infringement, merchantability and fitness for a particular purpose are expressly disclaimed.
Registration and Membership is no longer required for downloading files or interacting with Digital Raindrops, posting a comment or topic in the forum does use Captcha to reduce spammers.
This website is a tool to support and promote WordPress and Artisteer theme development, please support, share and give credit for any benefits you gain from the tutorials on this website.