Forums › Forums › Search & Filter Pro › Execute jquery script after product_cat change?
- This topic has 1 reply, 2 voices, and was last updated 7 years ago by Trevor.
-
Anonymous(Private) October 24, 2017 at 7:57 pm #138265
Hi, I hope you’re doing well.
I’m thinking to add a 2 lines scripts to make background header change when the user change the category (product_cat) in: http://www.argtravelagency.com.ar/viajes-a/paquetes/america/cuba/
I have setup ACF fields, so I have a flag, and background image for each category (just brasil and cuba at the moment).
Can you point me in the right direction as which file should I modify to do this? I just need to execute a script like $(“#selector”).css(“background-url”, “http://url/<?php echo $header; ?>”);
I hope you can help! Thank you!
Trevor(Private) October 25, 2017 at 9:23 am #138347There is no set answer for a question like that. It first depends, in the form settings, what Display Results Method you are using. In turn, this will determine what template php file you are using, as you code will need to fetch the data from the ACF field. However, javascript is not the way. Use PHP instead to fetch the ACF data, and then create some inline CSS based on what is fetched. I wrote something like this a while ago, where on each post the user could select an image to be used as a parallax background image at the top of the post. The code looked like this (used in the loop part of the page template):
<?php $banner_image = get_field('banner_image'); if ( !empty($banner_image) ) { echo '<style>.banner-image-wrapper {background-image: url("' . $banner_image['url'] . '");background-repeat: no-repeat;background-size: cover;}</style>'; } else { echo '<style>.banner-image-wrapper {display: none;}</style>'; } ?>
and there is a row in the template that has that class attached.
-
AuthorPosts