Specific header image for specific category? (87 posts)

  1. raindance
    Posted 4 years ago #

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

    Thank you!

  2. raindance
    Posted 4 years ago #

    Ok here is what I'm finding...
    Yahooo for blog posts assigned to the category "blog" by inserting the cat id in the array...works PERFFECTLY. So easy, so perfect.

    The one where it didn't work was a page instead of a blog post I assigned to the category blog.

    Does the code only work for posts, not for pages?
    Something different I need to do other than assign an existing page to the category "Blog"?

    Example..I have the page "flight deals" in the menu under Blog menu item
    It's a page which I assigned to the category Blog but it's still showing regular site headers...?

    Amazing commenting...so great!

  3. raindance
    Posted 4 years ago #

    So I've played around with it and indeed it works perfectly for single posts, just as you say! Fantastic!

    I was also hoping it work for pages as most of the content I have so far is as pages not posts.

    Can it also be made to work with pages as well as posts?
    (Please don't kill me) :-)

  4. raindance
    Posted 4 years ago #

    Actually I have another snag with the posts...I must be doing something wrong

    I made a post called "flight deals test post"
    I assigned it to a new sub category "flight-deals" (slug)
    This sub category is assigned to "juicy-travels-blog"
    I have a folder /graphene-child/images/custom-headers/juicy-travels/blog
    and within that folder I have

    But the test post flight deals only shows headers from the main /juicy-travels-blog/ folder, not the /flight-deals/folder.

    I've tried assigning the post to just the sub cat flight-deals and to both juicy-travels blog and flight-deals. Either way it doesn't show the headers from the /flight-deals/ folder.

    What step did I miss? :-)

  5. raindance
    Posted 4 years ago #

    Hey! I was wrong! I had to clear my cache a few times and that part works great..never mind, sorry!

    So the only potentially big question is...can we also make this work for pages as well as posts?

  6. raindance
    Posted 4 years ago #

    See how on the main blog category page (perfect)

    The bottom one called Flight Deals is a page...but so when you click on it you see the main site header not the blog header...I was hoping to be able to include both posts and pages in a category and have them show the header assigned to that category, like "blog"...

  7. Marventus
    Posted 4 years ago #

    Hi again,

    I just got back home.
    I'm glad to know it is working as intended!

    As for pages, well, it was never meant to work for pages, because you mentioned you wanted custom images for category archives and single posts. Pages and posts are two distinct types of content that are organized differently, so you can't really assign categories to pages. Posts are organized inside a category hierarchy, and pages inside a page hierarchy, both of which are separate.
    This is why I'm a little confused as to what you mean when you say:

    The one where it didn't work was a page instead of a blog post I assigned to the category blog.

    What I would do if I were you, is turn "Flight Deals" into a post, and assign it the Level 1 category "juicy-travels-blog" and all the sub-categories you desire, and that should force the custom images to display.

    Let me know if this makes sense to you.

  8. raindance
    Posted 4 years ago #

    Actually I always wanted it to be for pages and posts...I just read back through the beginning of our thread here and I did say that. I'm wondering if it might be do-able since my original code from Syahir was working for regular pages...just not the category archive page.

    Let me try to put it back to what he originally gave me and confirm that this is true...

  9. raindance
    Posted 4 years ago #

    Well I was totally wrong! It didn't work for pages.
    So actually..what we have now is fine because it just occurred to me I can use a featured image and just make it bigger than the header size so I can always assign a single relevant image for a page, it just won't have the benefit of being part of that random rotating from a folder option. I can totally live with that.

    Do we know of any custom header option for PAGES not posts that lets you assign random images from a folder like we did for the posts? :-)

    Sorry if I confused you or was confused myself...I thought we were doing it for pages and posts but if it can't be done then it can't be done and a single specific header on a page will work. I'd rather be able to do like we are doing and give a page a random rotation but it's not all that important.

    I think what you have done is so wonderful...thank you so much! And I really so impressed with your commenting...that sure makes it easy for someone else to follow it.

    Is it ok if I post it with credit to you on the Graphene forum so I can close out those threads?

    I am so so grateful to you...I spent weeks trying to solve this one! THANK YOU!

  10. Marventus
    Posted 4 years ago #

    Syahir's original code checks whether it is a category or a single post at the very beginning:

    if ( is_category() || is_single() ){

    so I would be surprised that it would work for pages as well, because that statement should return false for pages. The test for whether you are inside a page or not is


    That being said, you could still try to turn the page in question into a post and that should do the trick.

  11. raindance
    Posted 4 years ago #

    Yes you were right :-) Of course.

  12. Marventus
    Posted 4 years ago #

    I was editing my post when you answered and I don't know if you saw my last sentence, so here it goes again just in case: can Flight Deals be turned into a post instead of leaving it as a page, or would you need to include other pages in there as well?
    The code could be reworked to fit pages as well, but I would have to rethink the whole thing, so unless you really need to use pages, I don't know if it's worth the effort.

  13. raindance
    Posted 4 years ago #

    Well...I think so long as I can assign a single image to a particular page it's not worth the effort.
    If it were a plug in or something I'd say it would be nice if it could do both. By the way this would be a very popular plugin I think! :-)

    You did such an awesome thing for me to do this...thank you so very much.

    How would I contact you directly if I had a project?

  14. raindance
    Posted 4 years ago #

    And is ok to post this on the Graphene forum on your behalf to close out my three open threads on this topic? :-) I think other people will really be able to benefit from this!

  15. Marventus
    Posted 4 years ago #

    I am glad you are overall happy with the script. I'll try to see if I can make some time during the weekend to make it work with pages, but I can't make any promises.
    As for your contact request, you can e-mail me at wp-forums[atsymbol]elblawg[period]com. Sorry for the convoluted address, but I like to keep my inbox as span-free as possible, :-).
    Oh, you can totally share the link to the script: if I can make it work for pages, I'll simply update the code in the Pastebin.

  16. raindance
    Posted 4 years ago #

    Thank you so so so so much!!! I am so grateful!!!

  17. Marventus
    Posted 4 years ago #

    You are welcome, :-)

  18. Marventus
    Posted 4 years ago #

    I managed to make it work for pages too!
    Booya! :-)
    Here is the new version.


  19. raindance
    Posted 4 years ago #

    Wooohoooooooo no way really?? You ROCK! You are my hero :-)

    I'll post it in Graphene now...your ears must have been burning...someone always very helpful in that forum just said "wow so happy to see you solved it finally" as he's watching this thread also...and there you are with an even better solution!! Yipppeeee!!!


  20. raindance
    Posted 4 years ago #

    So Im thinking I must be doing something wrong...
    I've got the same..

    And the page is

    Its assigned to the category Blog (slug = juicy-travels-blog)
    I use Map categories to pages (it doesn't seem to show sub categories hierarchy though)

    But that page still shows the general site headers?
    Where have I gone wrong? :-)

  21. Marventus
    Posted 4 years ago #

    I think the Map Categories plugin might be the culprit.
    What happens if you create a new parent page, say Page Test (slug page-test), create a folder page-test inside images/custom-headers/, upload some images to that folder, and include the page ID in the $custom_image_ids array? Do custom images appear for the Page Test?

  22. raindance
    Posted 4 years ago #

    Ok will try it now...thanks!
    Sorry...server was down all morning, arrgh.

    Also did you get my email?

  23. raindance
    Posted 4 years ago #

    I just added the page id in like this:
    $custom_image_ids = array(52,220); // modify at will

    But it still doesn't show the images from the /custom-headers/juicy-travels-blog/

    Page id is 220, slug is flight-deals

    I tried disabling map categories to plug in page but realized then it has no idea that the page id goes to that blog category, nor anyway to assign pages to categories, right? So I re-activated it.

    It's not a disaster, I can use single images, but if I'm just doing something wrong then I ought to correct it.

    It's still working good for the blog posts and category archive page.

  24. raindance
    Posted 4 years ago #

    Ohhhhhhh my fault entirely...
    I thought the flight-deals needed to be IN the juicy-travels-blog folder...but no it needed to up a level...
    And VOILA works perfect...sorry! My fault!

    So the trick is to be sure for pages to:
    1. Put the page id in the array with the category id
    2. put the folder named after slug of page title in the images/custom-headers/ folder, not inside the slug named folder of the parent category.

    Which now that I read it for the third time I think you explained perfectly and I just missed it...yeay!

    So wonderful to have this dialed in...THANK YOU! :-)

  25. Marventus
    Posted 4 years ago #

    Hi Laura! Good thing you were able to figure it out.
    The reason why you needed to place your page images inside custom-headers is because that page does not belong in the category hierarchy, and obeys a different hierarchy. The fact that you force WP to treat a page as a category or perhaps to display posts inside pages, does not have any impact on your content organization: Flight Deals is still a Level 1 page and will be treated as such by WP.
    Let me know if this makes sense to you.

  26. raindance
    Posted 4 years ago #

    It totally makes sense, thank you so much for explaining it so clearly and for your patience with me! It's so fun to have it working...thank you!

  27. Romain51
    Posted 4 years ago #

    Hello there,

    As I told Raindance in another forum, I have some trouble implementing this new feature and code you created. I must be doing something wrong, but I don't see what exactly.

    - I created folders in my FTP that correspond with my categories' slug:
    - I uploaded in these folders appropriate jpeg images (they work all of them if I use them separately as a header)
    - I putted the code you created into my functions.php file (and I modified it, so that the ID of my categories are in it)
    - I checked the 'Random header' box on graphene header interface

    Unfortunately as a result I don't get any custom headers displayed...
    Before I deleted them on the FTP, I got the default header images displayed. Now that I deleted them on the FTP, I get no header at all. So it seams that it doesn't pick any images from custom header folder.

    Any idea what I could try?

    I saw that Raindance is using a child theme. could it be the problem, something to adapt in the code ? (Graphène is my main theme, I'm using only one theme.)

    Many thanks for your help,

  28. Romain51
    Posted 4 years ago #

    Oh yes I forgot to tell:
    I'm using WordPress 3.1.2 and Graphene 1.3


  29. Marventus
    Posted 4 years ago #

    Hi Romain,

    Did you try clearing your browser cache?
    Also, do you have any caching plugins installed on your site, such as WP Super Cache or W3 Total Cache? Those plugins are not compatible with rotating header images, since they cache (store) a static version of your blog pages. If you have one of these plugins installed, try to regenerate the cache from the plugin options see if there are any changes.

    I can guarantee the code works on WP 3.2.1 and Graphene 1.5.5 (i.e., both latest versions), but I haven't tested it older versions. Another thing worth mentioning is that I tested this code inside a Graphene child theme, not on the actual theme itself.

    I hope these pointers are helpful. If you still can't figure it out, let me know.


  30. Romain51
    Posted 4 years ago #

    Hi Marventus,

    Thanks so much for the answer. Yes I cleaned my cache (I do not use Cache plugins), but it didn't solve the problem.
    In my site, rotating headers worked with default images and default graphene feature, so I don't think this is the issue.
    I guess the problem is :
    either on not using a child theme, or on not using the latest version of Graphene (or wordpress, but I don't think so).

    I'll have a look at it later today and let you know.

Topic Closed

This topic has been closed to new replies.

About this Topic