Website link: https://colindedeugd.nl/stories
I have build a website with Wordpress and Divi. I am running into an issue, I hope you know the problem!
I have a custom Divi Blog Module. This not only grabs the default information from my blog posts, but also the info from a custom ACF image field (this was done with the help of Divi support, and some changes to my child theme and seems to work). The code below should then load the image from this custom field (currently set as Image URL return format) and input it as the module background. It get's as far as loading the correct image ID (I checked this with the inspect element tool) but fails to properly load the image. I hope someone knows what is going wrong! Here's the Javascript code I added to the page:
Код: Выделить всё
jQuery(document).ready(function($) {
// Searches for the Divi Blog Modules with this CSS Class where I want the background replaced
var $module = $('.acf-blog-bg');
// Checks if the module exists on the page
if ($module.length) {
// Retrieve the URL of the featured image using PHP
var imageUrl = "";
// Check if the image URL is not empty
if (imageUrl !== '') {
// Sets the background of the module to the URL of the image file
$module.css('background-image', 'url(' + imageUrl + ')');
}
}
});
For some additional context:
This was added to Blog.php (a copy of the Blog.php Module in my child theme) at around line 1640, to grab the data from the custom image field
Код: Выделить всё
$featured_portrait = get_post_meta($post->ID, 'featured_portrait', true) ? get_post_meta($post->ID, 'featured_portrait', true) : "";
if($featured_portrait != "") {
echo '';
}
Код: Выделить всё
function divi_custom_blog_module() {
get_template_part( '/includes/Blog' );
$dcfm = new custom_ET_Builder_Module_Blog();
remove_shortcode( 'et_pb_blog' );
add_shortcode( 'et_pb_blog', array( $dcfm, '_shortcode_callback' ) ); }
add_action( 'et_builder_ready', 'divi_custom_blog_module' );
function divi_custom_blog_class( $classlist ) {
// Blog Module 'classname' overwrite.
$classlist['et_pb_blog'] = array( 'classname' => 'custom_ET_Builder_Module_Blog',);
return $classlist;
}
add_filter( 'et_module_classes', 'divi_custom_blog_class' );
Источник: https://stackoverflow.com/questions/781 ... background
Мобильная версия