Created
January 19, 2016 16:41
-
-
Save mohsinrasool/aca02c3d243ed320d8b9 to your computer and use it in GitHub Desktop.
Overriding Divi's et_pb_fullwidth_portfolio shortcode
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_action('the_post', 'cs_setup_theme'); | |
function cs_setup_theme() { | |
//var_dump($_REQUEST); | |
if(is_page()) { | |
if(shortcode_exists( 'et_pb_fullwidth_portfolio' )) { | |
remove_shortcode('et_pb_fullwidth_portfolio'); | |
add_shortcode('et_pb_fullwidth_portfolio', 'cs_et_pb_fullwidth_portfolio'); | |
} | |
} | |
} | |
function cs_et_pb_fullwidth_portfolio( $atts ) { | |
extract( shortcode_atts( array( | |
'title' => '', | |
'module_id' => '', | |
'module_class' => '', | |
'fullwidth' => 'on', | |
'include_categories' => '', | |
'posts_number' => '', | |
'show_title' => 'on', | |
'show_date' => 'on', | |
'background_layout' => 'light', | |
'auto' => 'off', | |
'auto_speed' => 7000, | |
), $atts | |
) ); | |
$args = array(); | |
if ( is_numeric( $posts_number ) && $posts_number > 0 ) { | |
$args['posts_per_page'] = $posts_number; | |
} else { | |
$args['nopaging'] = true; | |
} | |
if ( '' !== $include_categories ) { | |
$args['tax_query'] = array( | |
array( | |
'taxonomy' => 'project_category', | |
'field' => 'id', | |
'terms' => explode( ',', $include_categories ), | |
'operator' => 'IN' | |
) | |
); | |
} | |
$projects = et_divi_get_projects( $args ); | |
ob_start(); | |
if( $projects->post_count > 0 ) { | |
while ( $projects->have_posts() ) { | |
$projects->the_post(); | |
?> | |
<div id="post-<?php the_ID(); ?>" <?php post_class( 'et_pb_portfolio_item ' ); ?>> | |
<?php | |
$thumb = ''; | |
$width = 320; | |
$width = (int) apply_filters( 'et_pb_portfolio_image_width', $width ); | |
$height = 241; | |
$height = (int) apply_filters( 'et_pb_portfolio_image_height', $height ); | |
list($thumb_src, $thumb_width, $thumb_height) = wp_get_attachment_image_src( get_post_thumbnail_id( get_the_ID() ), array( $width, $height ) ); | |
$orientation = ( $thumb_height > $thumb_width ) ? 'portrait' : 'landscape'; | |
if ( '' !== $thumb_src ) : ?> | |
<div class="et_pb_portfolio_image <?php esc_attr_e( $orientation ); ?>"> | |
<a href="<?php the_permalink(); ?>"> | |
<img src="<?php esc_attr_e( $thumb_src); ?>" alt="<?php esc_attr_e( get_the_title() ); ?>"/> | |
<div class="meta"> | |
<span class="et_overlay"></span> | |
<div class="table"> | |
<div class="cell"> | |
<?php if ( 'on' === $show_title ) : ?> | |
<h3><?php the_title(); ?></h3> | |
<?php endif; ?> | |
<?php if ( 'on' === $show_date ) : ?> | |
<p class="post-meta"><?php the_field('year') ?> / <?=get_post_meta(get_the_ID(),'wpcf-feature', true)?> / <?=get_post_meta(get_the_ID(),'wpcf-genre', true)?></p> | |
<?php endif; ?> | |
</div> | |
</div> | |
</div> | |
</a> | |
</div> | |
<?php endif; ?> | |
</div> | |
<?php | |
} | |
} | |
wp_reset_postdata(); | |
$posts = ob_get_clean(); | |
$class = " et_pb_bg_layout_{$background_layout}"; | |
$output = sprintf( | |
'<div%4$s class="et_pb_fullwidth_portfolio %1$s%3$s%5$s" data-auto-rotate="%6$s" data-auto-rotate-speed="%7$s"> | |
%8$s | |
<div class="et_pb_portfolio_items clearfix" data-columns=""> | |
%2$s | |
</div><!-- .et_pb_portfolio_items --> | |
</div> <!-- .et_pb_fullwidth_portfolio -->', | |
( 'on' === $fullwidth ? 'et_pb_fullwidth_portfolio_carousel' : 'et_pb_fullwidth_portfolio_grid clearfix' ), | |
$posts, | |
esc_attr( $class ), | |
( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ), | |
( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' ), | |
( '' !== $auto && in_array( $auto, array('on', 'off') ) ? esc_attr( $auto ) : 'off' ), | |
( '' !== $auto_speed && is_numeric( $auto_speed ) ? esc_attr( $auto_speed ) : '7000' ), | |
( '' !== $title ? sprintf( '<h2>%s</h2>', esc_html( $title ) ) : '' ) | |
); | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment