Skip to content

Instantly share code, notes, and snippets.

@smeyer
Created November 23, 2015 19:12
Show Gist options
  • Save smeyer/1645c5d2f694c06590dd to your computer and use it in GitHub Desktop.
Save smeyer/1645c5d2f694c06590dd to your computer and use it in GitHub Desktop.
<?php
echo do_shortcode( '[searchandfilter id="1050"]' );
// Get the correct featured image size
$post_featured_image_size = avada_get_portfolio_image_size( $current_page_id );
$post_featured_image_size_dimensions = avada_get_image_size_dimensions( $post_featured_image_size );
// Set picture size as data attribute; needed for resizing placeholders
$data_picture_size = 'auto';
if ( $post_featured_image_size != 'full' ) {
$data_picture_size = 'fixed';
}
echo sprintf( '<div class="fusion-portfolio-wrapper" data-picturesize="%s" data-pages="%s">', $data_picture_size, $portfolio_posts_to_display->max_num_pages );
// For non one column layouts check if column spacing is used, and if, how big it is,
$custom_colulmn_spacing = FALSE;
if ( ! strpos( $current_page_template, 'one' ) ) {
// Page option set
if ( fusion_get_page_option( 'portfolio_column_spacing', $current_page_id ) != NULL ) {
$custom_colulmn_spacing = TRUE;
$column_spacing = fusion_get_page_option( 'portfolio_column_spacing', $current_page_id ) / 2;
echo sprintf( '<style type="text/css">.fusion-portfolio-wrapper{margin: 0 %spx;}.fusion-portfolio-wrapper .fusion-col-spacing{padding:%spx;}</style>', ( -1 ) * $column_spacing, $column_spacing );
// Page option not set, but theme option
} else if( Avada()->settings->get( 'portfolio_column_spacing' ) ) {
$custom_colulmn_spacing = TRUE;
$column_spacing = Avada()->settings->get( 'portfolio_column_spacing' ) / 2;
echo sprintf( '<style type="text/css">.fusion-portfolio-wrapper{margin: 0 %spx;}.fusion-portfolio-wrapper .fusion-col-spacing{padding:%spx;}</style>', ( -1 ) * $column_spacing, $column_spacing );
}
}
// Loop through all the posts retrieved through our query based on chosen categories
while ( have_posts() ): the_post();
// Set the post permalink correctly; this is important for prev/next navigation on single portfolio pages
if ( $categories_to_display_ids &&
! $show_all_categories
) {
$post_permalink = fusion_add_url_parameter( get_permalink(), 'portfolioID', $current_page_id );
} else {
$post_permalink = get_permalink();
}
// Include the post categories as css classes for later useage with filters
$post_classes = '';
$post_categories = get_the_terms( $post->ID, 'resource-type' );
if ( $post_categories ) {
foreach ( $post_categories as $post_category ) {
$post_classes .= urldecode( $post_category->slug ) . ' ';
}
}
// Add the col-spacing class if needed
if ( $custom_colulmn_spacing ) {
$post_classes .= 'fusion-col-spacing';
}
// Add correct post class for image orientation
if ( $post_featured_image_size == 'full' ) {
$featured_image = wp_get_attachment_image_src( get_post_thumbnail_id(), 'full' );
$post_classes .= ' ' . avada_get_image_orientation_class( $featured_image );
}
// Render the resource post
echo sprintf( '<div class="fusion-portfolio-post post-%s %s">', get_the_ID(), $post_classes );
// Open fusion-portfolio-content-wrapper for text layouts
if ( strpos( $current_page_template, 'text' ) ) {
echo '<div class="fusion-portfolio-content-wrapper">';
}
// Render the video set in page options if no featured image is present
if ( ! has_post_thumbnail() &&
fusion_get_page_option( 'video', $post->ID )
) {
// For the portfolio one column layout we need a fixed max-width
if ( $current_page_template == 'portfolio-one-column' ) {
$video_max_width = '540px';
// For all other layouts get the calculated max-width from the image size
} else {
$video_max_width = $post_featured_image_size_dimensions['width'];
}
printf( '<div class="fusion-image-wrapper fusion-video" style="max-width:%s;">', $video_max_width );
echo fusion_get_page_option( 'video', $post->ID );
echo '</div>';
// On every other other layout render the featured image
} else {
$featured_image_markup = avada_render_first_featured_image_markup( $post->ID, $post_featured_image_size, $post_permalink, TRUE );
/* Preparing real masonry
if ( has_post_thumbnail()
) {
$featured_image_markup = str_replace( '"fusion-image-wrapper"', sprintf( '"fusion-image-wrapper" style="background-image: url(%s);"', $featured_image[0] ), $featured_image_markup );
}
*/
echo $featured_image_markup;
}
echo '<div class="fusion-portfolio-content">';
// Render the post title
if (get_field('hubspot_link') && get_field('download_or_link')=='Link') { $res_link = get_field('hubspot_link'); } else if (get_field('download_file') && get_field('download_or_link')=='Download') { $res_link = get_field('download_file'); }
echo '<h2 class="entry-title"><a href="' . $res_link . '">' . get_the_title($post->ID) . '</a></h2>';
// Render the post categories
echo sprintf( '<h4 class="res_cat">Category: %s</h4>', get_the_term_list( $post->ID, 'resource-category', '', ', ', '') );
echo sprintf( '<h4>Type: %s</h4>', get_the_term_list( $post->ID, 'resource-type', '', ', ', '') );
echo avada_render_rich_snippets_for_pages( false );
$post_content = '';
ob_start();
/**
* avada_portfolio_post_content hook
*
* @hooked avada_get_portfolio_content - 10 (outputs the post content)
*/
do_action( 'avada_portfolio_post_content', $current_page_id );
$post_content = ob_get_clean();
// For boxed layouts add a content separator if there is a post content
if ( $current_page_text_layout == 'boxed' &&
$post_content
) {
echo '<div class="fusion-content-sep"></div>';
}
echo '<div class="fusion-post-content">';
// Echo the post content
echo $post_content;
// On one column layouts render the "Learn More" and "View Project" buttons
if ( strpos( $current_page_template, 'one' ) ) {
echo '<div class="fusion-portfolio-buttons">';
// Render "Learn More" button
echo sprintf( '<a href="%s" class="fusion-button fusion-button-small fusion-button-default fusion-button-%s fusion-button-%s">%s</a>',
$post_permalink, strtolower( Avada()->settings->get( 'button_shape' ) ), strtolower( Avada()->settings->get( 'button_type' ) ), __( 'Learn More', 'Avada' ) );
// Render the "View Project" button only is a project url was set
if ( fusion_get_page_option( 'project_url', $post->ID ) ) {
echo sprintf( '<a href="%s" class="fusion-button fusion-button-small fusion-button-default fusion-button-%s fusion-button-%s">%s</a>', fusion_get_page_option( 'project_url', $post->ID ),
strtolower( Avada()->settings->get( 'button_shape' ) ), strtolower( Avada()->settings->get( 'button_type' ) ), __( ' View Project', 'Avada' ) );
}
echo '</div>';
}
echo '</div>'; // end post-content
// On unboxed one column layouts render a separator at the bottom of the post
if ( strpos( $current_page_template, 'one' ) &&
$current_page_text_layout == 'unboxed'
) {
echo '<div class="fusion-clearfix"></div>';
echo '<div class="fusion-separator sep-double"></div>';
}
echo '</div>'; // end resource-content
// Close fusion-portfolio-content-wrapper for text layouts
if ( strpos( $current_page_template, 'text' ) ) {
echo '</div>';
}
echo '</div>'; // end resource-post
endwhile;
echo '</div>'; // end portfolio-wrapper
// If infinite scroll with "load more" button is used
if ( Avada()->settings->get( 'grid_pagination_type' ) == 'load_more_button' ) {
echo sprintf( '<div class="fusion-load-more-button fusion-clearfix">%s</div>', apply_filters( 'avada_load_more_pots_name', __( 'Load More Posts', 'Avada' ) ) );
}
// Render the pagination
fusion_pagination( $portfolio_posts_to_display->max_num_pages, $range = 2, $portfolio_posts_to_display );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment