- This topic has 9 replies, 3 voices, and was last updated 4 years, 2 months ago by
roadlink.
-
AuthorPosts
-
February 25, 2022 at 5:30 am #2133203
roadlink
Hello,
I need to add a banner at the top of a number of WooCommerce category pages – I have created a new Element and the hook is set as woocommerce_before_main_content and the location as, for example, computers – this works great!
But – under the Computers category there are a number of sub-categories – eg: Notebooks, All-in-One PC etc – is there an option for having all sub-categories included in the location.
I can add them one by one but when I add new sub-category, I have to remember to add it here.
Which is very hard to rememberMany thanks
February 25, 2022 at 6:32 am #2133293David
StaffCustomer SupportHi there,
there isn’t a display option ( yet ) for sub-categories or child_of. It is something we’re looking into.
Its possible to use thegenerate_element_displayfilter to set custom display conditions:https://docs.generatepress.com/article/generate_element_display/
However, it would mean you have to ‘hard code’ the parent category terms in the filter, so if you added new parents then you have to edit the code.
Let me know if thats an option and i can see if we can provide a snippet for that.
February 25, 2022 at 7:45 am #2133376roadlink
Hi David,
I have 5 different parent category.
I plan to have different sliders for each parent categories and sub-categories under them.If it is possible, would be great to have snippet for one example.
I plan to add this shortcode. It works with or without php.
<?php echo do_shortcode(‘[metaslider id=”158760″]’); ?>
February 25, 2022 at 8:16 am #2133562David
StaffCustomer SupportYou could do this in one Hook:
<?php $cat = get_queried_object(); if ( $cat->term_id === 16 || $cat->parent === 16 ) { echo do_shortcode('[metaslider id="158760"]'); } if ( $cat->term_id === 30 || $cat->parent === 30 ) { echo do_shortcode('[metaslider id="4569123"]'); } // Add more if conditions if required. if ( $cat->term_id === 40 || $cat->parent === 40 ) { echo do_shortcode('[metaslider id="12321312"]'); } ?>The hook location will be for All Product Category Archives.
Each condition in that code eg.if ( $cat->term_id === 40 || $cat->parent === 40 ) {references the Category Term ID – in the example that is
40you need to update both instances to match the category you want to display the shortcode on.February 25, 2022 at 1:07 pm #2133878roadlink
Hi David,
That looks perfect. I am not very sure how to add it.
Element and hook or just to put it in my functions.php?
February 25, 2022 at 1:14 pm #2133886roadlink
I have added hook element. https://prnt.sc/2pbhcuGBUulE
Php and shortcode activated.
Location entire siteIt works. Is this the right way to do it?
February 25, 2022 at 2:51 pm #2133931Ying
StaffCustomer SupportHi there,
The hook location will be for All Product Category Archives.
February 25, 2022 at 2:56 pm #2133936roadlink
good to hear, thanks
February 25, 2022 at 2:59 pm #2133942Ying
StaffCustomer SupportNo problem 🙂
March 7, 2022 at 6:02 pm #2146090roadlink
thx
-
AuthorPosts
- You must be logged in to reply to this topic.