- This topic has 13 replies, 4 voices, and was last updated 5 months ago by
David.
-
AuthorPosts
-
October 26, 2022 at 10:46 am #2388433
Francisco
Hi,
I know that I can create a Header Element with the TITLE of each woocommerce category. But is there any way to add a DIFFERENT background image for each header? For example Woocommerce category “T-shirt” should have a specific background image and “Jackets” other one.
Thanks,
FranciscoOctober 26, 2022 at 10:56 am #2388450Leo
StaffCustomer SupportHi there,
You would need to create a separate header element for each category unfortunately as it’s category doesn’t have a dynamic property like featured image etc.
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 26, 2022 at 11:49 am #2388538Francisco
OK! I have discovered that I can choose to show the element in “Archive category prodcut” and then choose each category. (I will have to create one element for each woocommerce category, but for small clients it would be OK)
October 26, 2022 at 11:51 am #2388542Leo
StaffCustomer SupportSounds good π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 27, 2022 at 12:59 am #2389198mkjj
Wouldn’t it be easier to use category-specific CSS for the background-images? Seems to me a little bit over-the-top to use individual header elements for changing the background images. Do I miss anything?
Mike
October 27, 2022 at 5:03 am #2389539David
StaffCustomer SupportHi there,
a CSS option is definitely a possibility, or a custom developed Custom Field method could be used to do such a thing. But it really comes down to the user and how comfortable they are with a code solution over creating a new header element each time they add a category π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 27, 2022 at 11:18 am #2390320Francisco
Yes, custom CSS to each ID would be a good option also, thanks!
October 28, 2022 at 2:55 am #2391152David
StaffCustomer SupportCan you share a link to one of the categories where i can see you current header element ?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 28, 2022 at 10:19 am #2391953October 29, 2022 at 5:57 am #2392615David
StaffCustomer SupportOk, select the Container Block in that element, the one with the current background image.
In Advanced > Additional CSS Class(es) add:product_category_hero
Now we start with some CSS.
1. For each term slug you need to add a CSS rule like so:
body.term-slugname { --category-hero: url(https://your_domain/full_url_to_term_image); }
This will store an Image URL for the specific category term slug:
For example:
body.term-technology { --category-hero: url(https://your_domain/full_url_to_image_for_technology); } body.term-travel { --category-hero: url(https://your_domain/full_url_to_image_for_travel); } body.term-food { --category-hero: url(https://your_domain/full_url_to_image_for_food); }
So when we view the technology category, it will store the appropriate image in the
--category-hero
variable.2. Now we can add some CSS to load that variable image:
.product_category_hero { background-image: var(--category-hero) !important; }
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 29, 2022 at 9:08 am #2393146mkjj
Hi David,
do you use variables for a specific reason? By habit, I would have usedbody.term-food .product_category_hero
. Your solution is, of course, more elegant.Mike
October 29, 2022 at 10:10 am #2393201David
StaffCustomer Supportdo you use variables for a specific reason?
I do like CSS Variables, so i kind of look at them first.
But in this case, i had them to hand from another project that was auto-generating CSS variables.
So it was a quick copy and paste πDocumentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/October 29, 2022 at 3:06 pm #2393402Francisco
Excellent idea David!
October 30, 2022 at 4:50 am #2393730David
StaffCustomer SupportGlad to be of help
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/ -
AuthorPosts
- You must be logged in to reply to this topic.