Styling Different Headers Using Different Classes – via PHP
-
My Topic Title stinks, but I couldn’t think of any other way to describe what I’m trying to do – whooops.
So I’m using something like this:
<div id="header" <?php if ( has_tag('books')) { echo 'class="books"'; } ?>>
to add classes to my
#header
to help me style a different header for certain different SINGLE posts, post groupings (specific categories or pages), etc.What I Am Trying To Do (Recap): I would like to be able to specify different header specifications via CSS for individual posts (via tags probably), different pages, etc. I would also like for my home/main/most recent listing of posts to have a static header that will never change regardless of the tags the recent posts may have.
The example I gave works just splendidly and if the single post in question is displaying the ‘books’ tag, the header will be styled for the books class, but I would like to do more.
I would like to be able to specify classes for not just the ‘books’ tag but also for a ‘movies’ tag and whatever other non-overlapping tag (meaning, a post tagged with ‘books’ will never be tagged with ‘movies’) I might have that I might have a custom header image for.
ALSO, I would like my recent posts page’s header to remain as is and to not change based on my list of collective recent posts and their tags.
Is there any way to do this using the code that I have started?
I know that there are rotating header images plugins available, but my header stylization – image included – are all in my CSS stylesheet (background image) and I would like to keep it this way. The plugins I have seen have all used
<img src... />
to embed the header image (or media).I also know that I could create a bunch of custom templates and in each template, call a different header template with a different stylesheet, but… that just seems even more complicated and unnecessary than what I am already doing.
Or is it?
I’m no PHP expert of any sort and I need some help and would be really grateful if someone could offer it.
Please and thank you!
EDIT: I have discovered that:
<div id="header" <?php if (is_single(has_tag('books'))) { echo 'class="books"'; } ?>>
will style ONLY posts that are tagged with ‘books’ and NOT my main/home page, so at least -that- works to ensure my home page remains styled as is.
But I would still like to style more than one tag in one function if possible.
- The topic ‘Styling Different Headers Using Different Classes – via PHP’ is closed to new replies.