WordPress.org

Support

Support » Plugins and Hacks » Specific header image for specific category?

Specific header image for specific category?

  • Is there a way to specify a header image for a specific category?
    I’m using the Graphene theme.

    Thanks in advance for any help.

    Laura

Viewing 15 replies - 16 through 30 (of 86 total)
  • Hi again,

    So, good news: I managed to make custom images appear on my test blog’s header. The problem with Syahir’s version of the code (and thusly mine, heehee) was that he was trying to pass the $image variable to the graphene_header_image hook, but the variable used by the header image function is called header_img.
    Here is a new Pastebin paste with the updated code.
    Two things to keep in mind:
    1. Custom images will be retrieved from the folder:
    `graphene-child/images/custom-headers/[sub-cat]
    Where [subcat] is the name of the subcategory under the parent category juicy-travels-blog.
    2. Custom images need to be as wide (or wider) as the default header images in order to get displayed (this is not my doing, it’s set in Graphene’s functions.php).

    If you want to have this working in other categories, I can try to adjust the code accordingly. You will still need to create the folders and upload the pictures into each one manually though.

    Oh how wonderful, thank you, I’ll try it right now!

    BTW, I realized that I left the category value 4 from when I was testing this on my test blog, but you should change it to 52 in this line of code:

    if ( in_category(4) || post_is_in_descendant_category(4) ){

    Sorry about that!

    Hmmm…did I do something wrong?
    I have the same results.
    Blog header showing up great/random for the actual posts in that category.
    http://juicytravels.com/blog-post-test/
    But no blog header for the category archive page for the category “blog”
    http://juicytravels.com/category/juicy-travels-blog/
    I did change the cat id to 52.

    So I think we’re in the same spot as we started…working well for the posts/pages within the category blog, but not for the actual blog main page/category archive page.

    Anything else to try? Or maybe I did something wrong?
    The only thing I did differently was to paste in the new code to my child functions file and change the 4 to 52 in two places.
    Did I miss something? 🙂

    Ok. I think I know what the problem is. My previous post was not clear enough. Let me try to explain.
    On my test site, the code Syahir’s shared last was not working (because of the variable problem I mentioned). The only thing I did was fix it.
    Now, what that code does is test if we are inside the post category (regardless of the sub-category), and if we are, it tries to look for images inside the directory

    grapehene-child/images/custom-headers/[sub-cat]

    However, when you are inside the blog archive page, there is no sub-cat value because you are in the parent blog category, which means the code will try to look for images inside

    grapehene-child/images/custom-headers/

    Since there are no images in that folder, the default images get displayed instead.

    I left it that way because I was simply testing to see if the code actually worked, and because you had mentioned you might want custom images for all categories, not just for the Blog. Now that we know the code does work, it is only a matter of adjusting it based on what you want.

    I hope this is more clear now, 🙂

    Awesome! Thank you for explaining again…sorry if I missed the point 🙂
    Ok so…if we can:
    I want to be able to have it pull images for a parent category, like Blog (let’s just do that one then figure out multiples)
    So…I want the parent category “blog” to pull images from a folder, in this case I named it for the slug title of the main category called juicy-travels-blog.
    Can we make the category archive page pull from the folder with the slug title?
    Right now it looks like the post/pages within the category “blog” are pulling from that folder, which is perfect. In other words, I want the parent page to also pull from the same folder so that they all look the same to start.
    Then…if I want sub-categories like your example slug title blog-jokes to pull from their own folder /custom-headers/blog-jokes it would, but if there is no such folder, it would just also pull from the main category slug titled folder images/custom-headers/juicy-travels-blog

    Does that make sense?

    Yeah, it makes perfect sense.
    For all posts under the category Blog (slug juicy-travels-blog):
    1. if there is a sub-cat folder with images, images should be retrieved from that folder (juicy-travels-blog/sub-cat);
    2. If there is no sub-cat folder, images should be retrieved from the parent folder (juicy-travels-blog).
    Please confirm if I’m understanding you well.

    Yes! Perfectly!

    And in a perfect world…I could do it for as many parent categories/sub categories as I wanted to…like can I add more of the line that calls the catid 52 in?
    Like
    if ( in_category(52) || post_is_in_descendant_category(52) ){
    if ( in_category(41) || post_is_in_descendant_category(41) ){
    if ( in_category(17) || post_is_in_descendant_category(17) )

    or whatever?
    Then when I add a new category which I want to control images, I can just add in that line to functions with a new cat id?

    Any luck? 🙂

    Hi Laura,

    I’m very close, but I have not being able to figure it out completely.

    Thank you for not giving up! 🙂

    Hi Laura,

    I just wanted to give you an update on this: I rewrote the code as per what we discussed, and I managed to display one set of custom images for the main cat from one folder and a different set for child cats from a sub-folder.
    I also made it so that you can specify what categories custom images should be looked for.
    What I am struggling with, is to force the display of main cat images when inside a sub cat that has not have a custom folder from which to retrieve images. However, I should be able to figure this out pretty soon.

    Cheers!

    Oh that’s wonderful news, thanks!
    I’m sure a lot of people with Graphene will be reallllly appreciative of this! Can’t wait to see it and play with it!

    Hi Laura,

    The script is finally ready! It is rather long and verbose, but it does the trick. You can get the code from here.

    I have included detailed instructions inside the script, so it is easier to understand for other people that might want to use it.

    Let me know if it works properly or if you encounter any problems.

    Cheers!

    Yippe…implementing now…you are awesome for doing this!
    Will report back in a moment…

    Thank you!

Viewing 15 replies - 16 through 30 (of 86 total)
  • The topic ‘Specific header image for specific category?’ is closed to new replies.