Moving Filterable Portfolio module to child theme - kary4/divituts GitHub Wiki
If you want to add some custom features to your filterable portfolio module and you don't want to lose the changes when you update/reinstall then you need to use child theme. More info here: https://github.com/kary4/divituts/wiki/divi-child-theme
Firstly you need to redefine the filterable portfolio module in child theme and then you can add any changes to the filterable portfolio module. Here is the steps you need to follow to move filterable Portfolio module to child theme
-
Create a child theme or simply download it from here: https://github.com/kary4/divituts/wiki/divi-child-theme
-
In the child theme folder create a new folder, for example
includesfolder. -
Now copy the
divi/includes/builder/module/FilterablePortfolio.phpfile into thechild-theme/includes/folder. -
Rename the file to something else, for example:
custom-FilterablePortfolio.php. -
Open up the custom-FilterablePortfolio.php file and replace this code (the first line):
class ET_Builder_Module_Filterable_Portfolio extends ET_Builder_Module_Type_PostBased
with:
class Custom_ET_Builder_Module_Filterable_Portfolio extends ET_Builder_Module_Type_PostBased
Also, replace this line:
$this->vb_support = 'on';
with:
$this->vb_support = 'off';
- Next open up functions.php file in your child theme folder and add the following code at the very bottom:
function custom_filterableportfolio_setup() {
get_template_part( 'includes/custom-FilterablePortfolio' );
$custom_portfolio = new Custom_ET_Builder_Module_Filterable_Portfolio();
remove_shortcode( 'et_pb_filterable_portfolio' );
add_shortcode( 'et_pb_filterable_portfolio', array( $custom_portfolio, '_render()' ) );
}
add_action( 'et_builder_ready', 'custom_filterableportfolio_setup' );
Just search for this code in the code above
if ( '' !== $thumb ) : ?>
<a href="<?php the_permalink(); ?>">
and replace it with
if ( '' !== $thumb ) : ?>
<a href="<?php echo ($thumb); ?>" class="et_pb_lightbox_image">
Now add this code to the Integration tag:
<script>
jQuery( document ).ready(function() {
jQuery( '.et_pb_filterable_portfolio' ).each(function () {
jQuery(this).on('click', '.et_pb_portfolio_filter a', function(e) {
e.preventDefault();
setTimeout(function(){
window.et_pb_image_lightbox_init(jQuery( '.et_pb_lightbox_image'));
},100);
});
})
});
</script>
In the cfwpm.php file right before
</div><!-- .et_pb_portfolio_item -->
add
<?php the_excerpt(); ?>
Right before:
if ( '' !== $args['include_categories'] ) {
add:
$query_args['orderby'] = 'rand';
Right before:
if ( '' !== $args['include_categories'] ) {
add:
$query_args = array(
'orderby' => 'title',
'order' => 'ASC',
);
Another method: https://gist.github.com/indikatordesign/069c0b7f363977e092bb5193bdf74133