Select Page
Advertisements

To randomize the order of the portfolio grid, follow these steps:

  1. 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; 
  1. 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.
  2. 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 );
} 
  1. 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 );
}
} 
  1. 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.
  2. 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',
); 
  1. Replace above code with the following:
$query_args = array(
'posts_per_page' => (int) $args['posts_number'],
'post_type' => 'project',
'post_status' => 'publish',
'orderby' => 'rand'
); 
  1. That’s it! Your posts in the portfolio grid should now be randomized.