' . $the_cats . '
';
}
$return_data['portfolios'][] = [
'title' => get_the_title( $id ),
'thumbnail_type' => $thumbnail_type,
'image_size_dimensions' => $image_size_dimensions,
'video' => $video,
'image_data' => $image_data,
'rich_snippets' => $rich_snippets,
'post_categories' => $post_categories,
'project_url' => $project_url,
'content' => $content,
'term_list' => $term_list,
'permalink' => $permalink,
'post_title' => $post_title,
'post_terms' => $post_terms,
'permalink' => $permalink,
'has_manual_excerpt' => has_excerpt() ? true : null,
];
}
wp_reset_postdata();
}
$return_data['regular_images_found'] = $regular_images_found;
echo wp_json_encode( $return_data );
die();
}
/**
* Render the shortcode
*
* @access public
* @since 1.0
* @param array $args Shortcode parameters.
* @param string $content Content between shortcode.
* @return string HTML output.
*/
public function render( $args, $content = '' ) {
global $fusion_settings, $fusion_library;
$defaults = FusionBuilder::set_shortcode_defaults( self::get_element_defaults(), $args, 'fusion_portfolio' );
$defaults['column_spacing'] = FusionBuilder::validate_shortcode_attr_value( $defaults['column_spacing'], '' );
if ( ! isset( $args['portfolio_layout_padding'] ) ) {
$padding_values = [];
$padding_values['top'] = ( isset( $args['padding_top'] ) && '' !== $args['padding_top'] ) ? $args['padding_top'] : Fusion_Sanitize::size( $fusion_settings->get( 'portfolio_layout_padding', 'top' ) );
$padding_values['right'] = ( isset( $args['padding_right'] ) && '' !== $args['padding_right'] ) ? $args['padding_right'] : Fusion_Sanitize::size( $fusion_settings->get( 'portfolio_layout_padding', 'right' ) );
$padding_values['bottom'] = ( isset( $args['padding_bottom'] ) && '' !== $args['padding_bottom'] ) ? $args['padding_bottom'] : Fusion_Sanitize::size( $fusion_settings->get( 'portfolio_layout_padding', 'bottom' ) );
$padding_values['left'] = ( isset( $args['padding_left'] ) && '' !== $args['padding_left'] ) ? $args['padding_left'] : Fusion_Sanitize::size( $fusion_settings->get( 'portfolio_layout_padding', 'left' ) );
$defaults['portfolio_layout_padding'] = implode( ' ', $padding_values );
}
if ( '0' === $defaults['column_spacing'] ) {
$defaults['column_spacing'] = '0.0';
}
if ( '0' === $defaults['offset'] ) {
$defaults['offset'] = '';
}
// Backwards compatibility for old param name.
if ( 'grid' === $defaults['layout'] && ! isset( $args['text_layout'] ) ) {
$defaults['boxed_text'] = 'no_text';
}
if ( $defaults['boxed_text'] ) {
$defaults['text_layout'] = $defaults['boxed_text'];
}
if ( 'grid-with-excerpts' === $defaults['layout'] || 'grid-with-text' === $defaults['layout'] ) {
$defaults['layout'] = 'grid';
}
if ( 'default' === $defaults['text_layout'] ) {
$defaults['text_layout'] = $fusion_settings->get( 'portfolio_text_layout', false, 'unboxed' );
}
if ( 'full-content' === $defaults['content_length'] ) {
$defaults['content_length'] = 'full_content';
}
if ( 'default' === $defaults['content_length'] ) {
$defaults['content_length'] = $fusion_settings->get( 'portfolio_content_length', false, 'excerpt' );
}
if ( 'default' === $defaults['portfolio_title_display'] ) {
$defaults['portfolio_title_display'] = $fusion_settings->get( 'portfolio_title_display', false, 'all' );
}
if ( 'default' === $defaults['portfolio_text_alignment'] ) {
$defaults['portfolio_text_alignment'] = $fusion_settings->get( 'portfolio_text_alignment', false, 'left' );
}
if ( 'default' === $defaults['picture_size'] ) {
$image_size = $fusion_settings->get( 'portfolio_featured_image_size' );
if ( 'full' === $image_size ) {
$defaults['picture_size'] = 'auto';
} else {
$defaults['picture_size'] = 'fixed';
}
}
if ( 'masonry' === $defaults['layout'] ) {
$defaults['picture_size'] = 'auto';
}
if ( 'default' === $defaults['pagination_type'] ) {
$defaults['pagination_type'] = trim( str_replace( [ '_scroll', '_' ], [ '', '-' ], strtolower( $fusion_settings->get( 'portfolio_pagination_type', false, 'none' ) ) ), '-' );
}
if ( 'default' === $defaults['strip_html'] ) {
$defaults['strip_html'] = $fusion_settings->get( 'portfolio_strip_html_excerpt', false, 'yes' );
} else {
$defaults['strip_html'] = ( 'yes' === $defaults['strip_html'] );
}
extract( $defaults );
self::$args = $defaults;
// Set the image size for the slideshow.
$this->set_image_size();
// As $excerpt_words is deprecated, only use it when explicity set.
if ( $excerpt_words || '0' === $excerpt_words ) {
$excerpt_length = $excerpt_words;
}
$title = true;
$categories = true;
// Check the title and category display options.
if ( self::$args['portfolio_title_display'] ) {
$title_display = self::$args['portfolio_title_display'];
$title = ( 'all' === $title_display || 'title' === $title_display );
$categories = ( 'all' === $title_display || 'cats' === $title_display );
}
// Add styling for alignment and padding.
$styling = '';
if ( 'carousel' !== self::$args['layout'] && 'no_text' !== self::$args['text_layout'] ) {
$layout_padding = ( 'boxed' === self::$args['text_layout'] && '' !== self::$args['portfolio_layout_padding'] ) ? 'padding: ' . self::$args['portfolio_layout_padding'] . ';' : '';
$layout_alignment = 'text-align: ' . self::$args['portfolio_text_alignment'] . ';';
$styling .= '';
}
$portfolio_query = $this->query();
if ( ! $portfolio_query->have_posts() ) {
$this->portfolio_counter++;
return fusion_builder_placeholder( 'avada_portfolio', 'portfolio posts' );
}
$portfolio_posts = '';
if ( is_array( self::$args['cat_slugs'] ) && 0 < count( self::$args['cat_slugs'] ) && function_exists( 'fusion_add_url_parameter' ) ) {
$cat_ids = [];
foreach ( self::$args['cat_slugs'] as $cat_slug ) {
$cat_obj = get_term_by( 'slug', $cat_slug, 'portfolio_category' );
if ( isset( $cat_obj->term_id ) ) {
$cat_ids[] = $cat_obj->term_id;
}
}
$cat_ids = implode( ',', $cat_ids );
}
// Set a gallery id for the lightbox triggers on rollovers.
$gallery_id = '-rw-' . $this->portfolio_counter;
$lazy_load = $fusion_settings->get( 'lazy_load' );
// Loop through returned posts.
// Setup the inner HTML for each elements.
while ( $portfolio_query->have_posts() ) {
$portfolio_query->the_post();
$this->post_id = get_the_ID();
// Only add post if it has a featured image, or a video, or if placeholders are activated.
if ( has_post_thumbnail() || $fusion_settings->get( 'featured_image_placeholder' ) || fusion_get_page_option( 'video', $this->post_id ) ) {
// Reset vars.
$rich_snippets = '';
$post_classes = '';
$title_terms = '';
$image = '';
$post_title = '';
$post_terms = '';
$separator = '';
$post_content = '';
$buttons = '';
$learn_more_button = '';
$view_project_button = '';
$post_separator = '';
$element_orientation_class = '';
// For carousels we only need the image and a li wrapper.
if ( 'carousel' === $layout ) {
// Title on rollover layout.
if ( 'title_on_rollover' === $carousel_layout ) {
$show_title = 'default';
// Title below image layout.
} else {
$show_title = 'disable';
// Get the post title.
$fusion_portfolio_carousel_title = '' . $video . '
';
$image = apply_filters( 'fusion_portfolio_item_video', $video_markup, $video, $video_max_width );
} elseif ( $fusion_settings->get( 'featured_image_placeholder' ) || has_post_thumbnail() ) {
// Get the post image.
if ( 'full' === $this->image_size && class_exists( 'Avada' ) && property_exists( Avada(), 'images' ) ) {
Avada()->images->set_grid_image_meta(
[
'layout' => 'portfolio_full',
'columns' => $columns,
'gutter_width' => $column_spacing,
]
);
}
$image = fusion_render_first_featured_image_markup( $this->post_id, $this->image_size, get_permalink( $this->post_id ), true, false, false, 'default', $show_title, '', $gallery_id );
if ( class_exists( 'Avada' ) && property_exists( Avada(), 'images' ) ) {
Avada()->images->set_grid_image_meta( [] );
}
}
$portfolio_posts .= '' . $video . '
';
$image = apply_filters( 'fusion_portfolio_item_video', $video_markup, $video, $video_max_width );
} elseif ( $fusion_settings->get( 'featured_image_placeholder' ) || has_post_thumbnail() ) {
$responsive_images_columns = $columns;
$masonry_attributes = [];
$element_base_padding = 0.8;
// Masonry layout.
if ( 'masonry' === $layout ) {
// Set image or placeholder and correct corresponding styling.
if ( has_post_thumbnail() ) {
$post_thumbnail_attachment = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
$masonry_attribute_style = $lazy_load ? '' : 'background-image:url(' . $post_thumbnail_attachment[0] . ');';
} else {
$post_thumbnail_attachment = [];
$masonry_attribute_style = 'background-color:#f6f6f6;';
}
// Get the correct image orientation class.
if ( class_exists( 'Avada' ) && property_exists( Avada(), 'images' ) ) {
$element_orientation_class = Avada()->images->get_element_orientation_class( get_post_thumbnail_id(), $post_thumbnail_attachment, $defaults['portfolio_masonry_grid_ratio'], $defaults['portfolio_masonry_width_double'] );
$element_base_padding = Avada()->images->get_element_base_padding( $element_orientation_class );
}
$post_classes .= ' ' . $element_orientation_class;
$masonry_column_offset = ' - ' . ( (int) $column_spacing / 2 ) . 'px';
if ( false !== strpos( $element_orientation_class, 'fusion-element-portrait' ) ) {
$masonry_column_offset = '';
}
$masonry_column_spacing = ( (int) $column_spacing ) . 'px';
if ( 'no_text' !== $text_layout && 'boxed' === $text_layout &&
class_exists( 'Fusion_Sanitize' ) && class_exists( 'Fusion_Color' ) &&
'transparent' !== Fusion_Sanitize::color( self::$args['grid_element_color'] ) &&
0 !== Fusion_Color::new_color( self::$args['grid_element_color'] )->alpha
) {
$masonry_column_offset = ' - ' . ( (int) $column_spacing / 2 ) . 'px';
if ( false !== strpos( $element_orientation_class, 'fusion-element-portrait' ) ) {
$masonry_column_offset = ' + 4px';
}
$masonry_column_spacing = ( (int) $column_spacing - 4 ) . 'px';
if ( false !== strpos( $element_orientation_class, 'fusion-element-landscape' ) ) {
$masonry_column_spacing = ( (int) $column_spacing - 10 ) . 'px';
}
}
// Calculate the correct size of the image wrapper container, based on orientation and column spacing.
$masonry_attribute_style .= 'padding-top:calc((100% + ' . $masonry_column_spacing . ') * ' . $element_base_padding . $masonry_column_offset . ');';
// Check if we have a landscape image, then it has to stretch over 2 cols.
if ( '1' !== $columns && 1 !== $columns && false !== strpos( $element_orientation_class, 'fusion-element-landscape' ) ) {
$responsive_images_columns = (int) $columns / 2;
}
// Set the masonry attributes to use them in the first featured image function.
$masonry_attributes = [
'class' => 'fusion-masonry-element-container',
'style' => $masonry_attribute_style,
];
if ( $lazy_load && isset( $post_thumbnail_attachment[0] ) ) {
$masonry_attributes['data-bg'] = $post_thumbnail_attachment[0];
$masonry_attributes['class'] .= ' lazyload';
}
}
// Get the post image.
if ( 'full' === $this->image_size && class_exists( 'Avada' ) && property_exists( Avada(), 'images' ) ) {
Avada()->images->set_grid_image_meta(
[
'layout' => 'portfolio_full',
'columns' => $responsive_images_columns,
'gutter_width' => $column_spacing,
]
);
}
$image = fusion_render_first_featured_image_markup( $this->post_id, $this->image_size, $permalink, true, false, false, 'default', 'default', '', $gallery_id, 'yes', false, $masonry_attributes );
if ( class_exists( 'Avada' ) && property_exists( Avada(), 'images' ) ) {
Avada()->images->set_grid_image_meta( [] );
}
}
// Additional content for layouts using text.
if ( 'carousel' !== self::$args['layout'] && 'no_text' !== self::$args['text_layout'] ) {
// Get the rich snippets, if enabled.
$rich_snippets = avada_render_rich_snippets_for_pages( false );
// Get the post title.
if ( $title ) {
$post_title = avada_render_post_title( $this->post_id, true, false, '2', $permalink );
}
// Get the post terms.
if ( $categories ) {
$the_cats = get_the_term_list( $this->post_id, 'portfolio_category', '', ', ', '' );
if ( $the_cats ) {
$post_terms = '' . $the_cats . '
';
}
}
// Get the post content.
ob_start();
/**
* The fusion_portfolio_shortcode_content hook.
*
* @hooked content - 10 (outputs the post content)
*/
do_action( 'fusion_portfolio_shortcode_content' );
$stripped_content = ob_get_clean();
// For boxed layouts add a content separator if there is a post content.
if ( 'boxed' === $text_layout && $stripped_content && 'masonry' !== self::$args['layout'] ) {
$separator = '' . $learn_more_button . $view_project_button . '
';
}
// Put it all together.
$post_content = '';
$post_content .= apply_filters( 'fusion_portfolio_grid_title', $post_title );
$post_content .= apply_filters( 'fusion_portfolio_grid_terms', $post_terms );
$post_content .= apply_filters( 'fusion_portfolio_grid_separator', $separator );
$post_content .= '
';
$post_content .= apply_filters( 'fusion_portfolio_grid_content', $stripped_content );
$post_content .= apply_filters( 'fusion_portfolio_grid_buttons', $buttons, $learn_more_button, $view_project_button );
$post_content .= '
';
} else {
// Get the rich snippets for grid layout without excerpts.
$rich_snippets = avada_render_rich_snippets_for_pages();
}
// Post separator for one column grid layouts.
if ( ( '1' === $columns || 1 === $columns ) && 'boxed' !== self::$args['text_layout'] && 'grid' === self::$args['layout'] ) {
$post_separator = '' . $rich_snippets . $image . $post_content . '
' . apply_filters( 'fusion_portfolio_grid_post_separator', $post_separator ) . '';
}
}
}
wp_reset_postdata();
// Wrap all the portfolio posts with the appropriate HTML markup.
// Carousel layout.
if ( 'carousel' === $layout ) {
self::$args['data-pages'] = '';
$main_carousel = '' . apply_filters( 'avada_load_more_posts_name', esc_attr__( 'Load More Posts', 'fusion-core' ) ) . '
';
}
$infinite_pagination = false;
if ( 'load-more-button' === $pagination_type || 'infinite' === $pagination_type ) {
$infinite_pagination = true;
}
$pagination .= fusion_pagination( $portfolio_query->max_num_pages, $fusion_settings->get( 'pagination_range' ), $portfolio_query, $infinite_pagination );
}
if ( 'masonry' === $layout ) {
$portfolio_posts = '