Advertisements
To randomize the order of the portfolio grid, follow these steps:
- Add the following code to the bottom of your child theme’s functions.php:
if ( ! function_exists( 'et_builder_add_main_elements' ) ) :
function et_builder_add_main_elements() {
require ET_BUILDER_DIR . 'main-structure-elements.php';
require 'main-modules.php';
}
endif;
- Now go to your theme’s folder Divi > includes > builder > main-modules.php. Copy main-modules.php and paste it into the root folder of your child theme.
- Edit your child theme’s main-modules.php file and look for the following code:
do_action( 'et_builder_modules_load' );foreach ( $et_builder_module_types as $module_type ) {
require_once( $module_type );
}foreach ( $et_builder_module_files as $module_file ) {
require_once( $module_file );
}
- Replace above code with the following:
do_action( 'et_builder_modules_load' );$codefile= ET_BUILDER_DIR . 'module/Portfolio.php';foreach ( $et_builder_module_types as $module_type ) {
require_once( $module_type );
}foreach ( $et_builder_module_files as $module_file ) {if($module_file == $codefile){
require_once( 'Portfolio.php' );
}else{
require_once( $module_file );
}
}
- Now go to your theme’s folder Divi > includes > builder > module > portfolio.php. Copy portfolio.php and paste it into the root folder of your child theme.
- Edit your child theme’s portfolio.php file and look for the following code:
$query_args = array(
'posts_per_page' => (int) $args['posts_number'],
'post_type' => 'project',
'post_status' => 'publish',
);
- Replace above code with the following:
$query_args = array(
'posts_per_page' => (int) $args['posts_number'],
'post_type' => 'project',
'post_status' => 'publish',
'orderby' => 'rand'
);
- That’s it! Your posts in the portfolio grid should now be randomized.
What about making changes to the divi sections via child theme. I want to add a toggle to all sections in the vb to add a css class, and I have written the code to make this happen and it works perfectly via adding the changes directly in divi’s main-structure-elements.php file, however, if I try to call it using the function you have provided it does not work correctly
I have been stumped trying to figure this out
Hello,
Thanks for this tips. The main-modules.php is not appear in folder builder ? Do you if there is an other name since 2018 ? Thank you
Hey, Greg. Sorry for the late reply. Have you checked into this solution?
https://divibooster.com/changing-the-portfolio-module-project-order/