function wm_shortcode_projects( $atts, $content = null ) { global $paged; if ( ! isset( $paged ) ) $paged = 1; extract( shortcode_atts( array( 'align' => 'left', 'category' => '', 'columns' => 4, 'count' => -1, 'desc_size' => 4, 'excerpt_length' => 'default', 'filter' => false, 'order' => 'new', 'pagination' => false, 'related' => false, 'scroll' => 0, 'scroll_stack' => false, 'tag' => '', 'thumb' => true, ), $atts ) ); if ( 'disable' === wm_option( 'cp-role-projects' ) ) return; $out = $filterContent = $wrapperClasses = ''; $imgSize = ( wm_option( 'general-projects-image-ratio' ) ) ? ( 'mobile-' . wm_option( 'general-projects-image-ratio' ) ) : ( 'mobile-ratio-169' ); //validation $align = ( 'right' === trim( $align ) ) ? ( trim( $align ) ) : ( 'left' ); $cols = ( 0 < absint( $columns ) && 7 > absint( $columns ) ) ? ( absint( $columns ) ) : ( 4 ); $colsDesc = ( 1 < absint( $desc_size ) && 7 > absint( $desc_size ) ) ? ( absint( $desc_size ) ) : ( 4 ); $count = ( $count ) ? ( intval( $count ) ) : ( -1 ); $orderMethod = array( 'all' => array( 'new', 'old', 'name', 'random' ), 'new' => array( 'date', 'DESC' ), 'old' => array( 'date', 'ASC' ), 'name' => array( 'title', 'ASC' ), 'random' => array( 'rand', '' ) ); $order = ( in_array( trim( $order ), $orderMethod['all'] ) ) ? ( $orderMethod[trim( $order )] ) : ( $orderMethod['new'] ); $thumb = ( $thumb ) ? ( ' has-thumbs' ) : ( false ); $classScroll = array( '', '', '' ); if ( $scroll && 999 < absint( $scroll ) ) $classScroll = array( ' scrollable auto', absint( $scroll ), ' auto-scroll' ); elseif ( $scroll ) $classScroll = array( ' scrollable', '', ' manual-scroll' ); if ( $scroll && $scroll_stack ) $classScroll[0] .= ' stack'; $defaultExcerpt = ( 1 == $cols ) ? ( 52 ) : ( 12 ); $excerptLength = ( 'default' != $excerpt_length ) ? ( absint( $excerpt_length ) ) : ( $defaultExcerpt ); $isotopeLayout = 'fitRows'; $filter = ( $filter && ! $classScroll[0] ) ? ( true ) : ( false ); $filterThis = ( $filter ) ? ( ' filter-this' ) : ( '' ); $wrapperClasses .= ( $filter ) ? ( ' filterable-content' ) : ( '' ); $wrapperClasses .= ( $related ) ? ( ' related-projects' ) : ( '' ); $wrapperClasses .= ( 1 == $cols ) ? ( ' single-columned' ) : ( '' ); if ( $related ) { global $post; $category = array(); $terms = get_the_terms( $post->ID , 'project-category' ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { foreach( $terms as $term ) { $category[] = $term->term_id; } } } elseif ( $category ) { if ( is_numeric( $category ) ) { $category = absint( $category ); } else { $category = get_term_by( 'slug', sanitize_title( $category ), 'project-category' ); $category = ( $category && isset( $category->term_id ) ) ? ( $category->term_id ) : ( null ); } } else { $category = null; } if ( $tag ) { if ( is_numeric( $tag ) ) { $tag = absint( $tag ); } else { $tag = get_term_by( 'slug', sanitize_title( $tag ), 'project-tag' ); $tag = ( $tag && isset( $tag->term_id ) ) ? ( $tag->term_id ) : ( null ); } } else { $tag = null; } //get project icons $projectIcons = array(); $terms = get_terms( 'project-type', 'orderby=name&hide_empty=0&hierarchical=0' ); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { foreach ( $terms as $term ) { $meta = get_option( 'wm-tax_project-type-' . $term->term_id ); $projectIcons[$meta['type'] . '[' . $term->slug . ']'] = array( $meta['icon'], $term->name ); } } if ( empty( $projectIcons ) ) $projectIcons = array( 'static-project' => array( 'wmicon-image', __( 'Image', 'lespaul_domain' ) ), 'slider-project' => array( 'wmicon-gallery', __( 'Image slider', 'lespaul_domain' ) ), 'video-project' => array( 'wmicon-video', __( 'Video', 'lespaul_domain' ) ), 'audio-project' => array( 'wmicon-audio', __( 'Audio', 'lespaul_domain' ) ) ); //get the projects wp_reset_query(); $queryArgs = array( 'paged' => $paged, 'post_type' => 'wm_projects', 'posts_per_page' => $count, 'ignore_sticky_posts' => 1, 'orderby' => $order[0], 'order' => $order[1] ); if ( $category ) $queryArgs['tax_query'][] = array( 'taxonomy' => 'project-category', 'field' => 'id', 'terms' => $category ); if ( $tag ) $queryArgs['tax_query'][] = array( 'taxonomy' => 'project-tag', 'field' => 'id', 'terms' => $tag ); if ( $tag && $category ) $queryArgs['tax_query']['relation'] = 'AND'; if ( $related && get_the_ID() ) $queryArgs['post__not_in'] = array( get_the_ID() ); $projects = new WP_Query( $queryArgs ); $pagination = ( $pagination ) ? ( wm_pagination( $projects, array( 'print' => false ) ) ) : ( '' ); $wrapperClasses .= ( $pagination ) ? ( ' paginated' ) : ( '' ); $wrapperClasses .= $thumb . $classScroll[2]; if ( $projects->have_posts() ) { $i = $row = 0; $out .= '<div class="wrap-projects-shortcode clearfix apply-top-margin' . $wrapperClasses . '">'; $out .= ( $related ) ? ( '<h3 class="separator-heading"><span class="text-holder">' . strip_tags( trim( $related ), '<strong><span><small><em><b><i>' ) . '</span><span class="pattern-holder"></span></h3>' ) : ( '' ); //filter output code if ( $filter ) { $filterContent .= '<div class="wrap-filter"><ul>'; if ( $category ) { //if parent category set - filter from child categories $parentCategory = get_term_by( 'id', $category, 'project-category' ); $filterContent .= '<li><a href="#" data-filter="*" class="active">' . sprintf( __( 'All <span>%s</span>', 'lespaul_domain' ), $parentCategory->name ) . '</a></li>'; $terms = get_term_children( $category, 'project-category' ); $count = count( $terms ); if ( ! is_wp_error( $terms ) && $count > 0 ) { $outFilter = array(); foreach ( $terms as $child ) { $term = get_term_by( 'id', $child, 'project-category' ); $outArray['<li><a href="#" data-filter=".project-category-' . $term->slug . '">' . $term->name . ' <span class="count">(' . $term->count . ')</span></a></li>'] = $term->name; } asort( $outArray ); $outArray = array_flip( $outArray ); $filterContent .= implode( '', $outArray ); } } else { //no parent category - filter from all categories $filterContent .= '<li><a href="#" data-filter="*" class="active">' . __( 'All', 'lespaul_domain' ) . '</a></li>'; $terms = get_terms( 'project-category' ); $count = count( $terms ); if ( ! is_wp_error( $terms ) && $count > 0 ) { foreach ( $terms as $term ) { $filterContent .= '<li><a href="#" data-filter=".project-category-' . $term->slug . '">' . $term->name . ' <span class="count">(' . $term->count . ')</span></a></li>'; } } } $filterContent .= '</ul></div>'; } // if filter if ( $content ) { //if description (shortcode content) $out .= ( 'right' === $align ) ? ( '<div class="column col-' . ( $colsDesc - 1 ) . $colsDesc . '">' . $filterContent . '<div class="wrap-projects' . $filterThis . $classScroll[0] . '" data-layout-mode="' . $isotopeLayout . '" data-time="' . $classScroll[1] . '" data-columns="' . $cols . '">' ) : ( '<div class="column col-1' . $colsDesc . ' wrap-description">' . do_shortcode( $content ) . '</div><div class="column col-' . ( $colsDesc - 1 ) . $colsDesc . ' last">' . $filterContent . '<div class="wrap-projects' . $filterThis . $classScroll[0] . '" data-layout-mode="' . $isotopeLayout . '" data-time="' . $classScroll[1] . '" data-columns="' . $cols . '">' ); //if description on the right - open projects container and inner container only ELSE output content column and open projects container } else { //if no description (no shortcode content) $out .= $filterContent . '<div class="wrap-projects' . $filterThis . $classScroll[0] . '" data-layout-mode="' . $isotopeLayout . '" data-time="' . $classScroll[1] . '" data-columns="' . $cols . '">'; } $out .= ( ! $filter && ! $classScroll[0] && 1 != $cols ) ? ( '<div class="row">' ) : ( '' ); $alt = ''; while ( $projects->have_posts() ) : //output post content $projects->the_post(); $terms = get_the_terms( get_the_ID() , 'project-category' ); $termsClass = ''; $termsOutArray = array(); if ( ! is_wp_error( $terms ) && ! empty( $terms ) ) { foreach( $terms as $term ) { //$termsOutArray[] = '<a href="' . get_term_link( $term->slug, 'project-category' ) . '" class="item">' . $term->name . '</a>'; $termsOutArray[] = '<span class="item">' . $term->name . '</span>'; $termsClass .= ' project-category-' . $term->slug; } } $link = ( wm_meta_option( 'project-link-list' ) ) ? ( esc_url( wm_meta_option( 'project-link' ) ) ) : ( get_permalink() ); $linkAtts = ( 'target-blank' == wm_meta_option( 'project-link-list' ) ) ? ( ' target="_blank"' ) : ( '' ); $linkAtts .= ( trim( wm_meta_option( 'project-rel-text' ) ) ) ? ( ' rel="' . trim( wm_meta_option( 'project-rel-text' ) ) . '" data-rel="' . trim( wm_meta_option( 'project-rel-text' ) ) . '"' ) : ( ' data-rel=""' ); $overlayText = ( 'modal' == wm_meta_option( 'project-link-list' ) ) ? ( __( 'Zoom', 'lespaul_domain' ) ) : ( __( 'View', 'lespaul_domain' ) ); if ( trim( wm_meta_option( 'project-hover-text' ) ) ) $overlayText = trim( wm_meta_option( 'project-hover-text' ) ); if ( 0 < $excerptLength && has_excerpt() ) $excerptText = wp_trim_words( get_the_excerpt(), $excerptLength, '…' ); else $excerptText = ''; $icon = 'wmicon-image'; $iconTitle = __( 'Image', 'lespaul_domain' ); if ( wm_meta_option( 'project-type' ) ) { if ( isset( $projectIcons[wm_meta_option( 'project-type' )][0] ) ) $icon = $projectIcons[wm_meta_option( 'project-type' )][0]; if ( isset( $projectIcons[wm_meta_option( 'project-type' )][1] ) ) $iconTitle = $projectIcons[wm_meta_option( 'project-type' )][1]; } $projectOutput = array( 'category' => '<div class="project-category text-element">' . implode( ', ', $termsOutArray ) . '</div>', 'thumb' => wm_thumb( array( 'class' => 'post-thumb', 'size' => $imgSize, 'list' => true, 'link' => array( $link, wm_meta_option( 'project-link-list' ) ), 'placeholder' => true, 'a-attributes' => $linkAtts, 'overlay' => $overlayText, ) ), 'title' => '<h3 class="project-title text-element"><a href="' . $link . '"' . $linkAtts . ' class="' . wm_meta_option( 'project-link-list' ) . '">' . get_the_title() . '</a></h3>', 'type' => '<a class="project-icon ' . wm_meta_option( 'project-link-list' ) . '"' . $linkAtts . ' href="' . $link . '"><i class="' . $icon . '" title="' . $iconTitle . '"></i></a>', 'excerpt' => ( $excerptText ) ? ( '<div class="project-excerpt text-element">' . strip_tags( strip_shortcodes( $excerptText ) ) . '</div>' ) : ( '' ), ); if ( ! $filter && ! $classScroll[0] && 1 != $cols ) { $row = ( ++$i % $cols === 1 ) ? ( $row + 1 ) : ( $row ); $out .= ( $i % $cols === 1 && 1 < $row ) ? ( '</div><div class="row">' ) : ( '' ); } $out .= '<article class="column col-1' . $cols . ' no-margin item item-' . get_the_ID() . $termsClass . $alt . '">'; $out .= ( $thumb ) ? ( $projectOutput['thumb'] ) : ( '' ); $out .= '<div class="text">'; $out .= $projectOutput['type']; $out .= $projectOutput['title']; $out .= $projectOutput['category']; $out .= $projectOutput['excerpt']; $out .= '</div>'; $out .= '</article>'; $alt = ( $alt ) ? ( '' ) : ( ' alt' ); endwhile; $out .= ( ! $filter && ! $classScroll[0] && 1 != $cols ) ? ( '</div>' ) : ( '' ); //end row if ( $content ) { //if description (shortcode content) $out .= ( 'right' === $align ) ? ( '</div>' . $pagination . '</div><div class="column col-1' . $colsDesc . ' last wrap-description">' . do_shortcode( $content ) . '</div>' ) : ( '</div>' . $pagination . '</div>' ); //if description on the right - close projects container and its inner container and output content column ELSE just close projects container and its inner container } else { //if no description (no shortcode content) $out .= '</div>' . $pagination; } $out .= '</div>'; } wp_reset_query(); if ( $classScroll[0] ) wp_enqueue_script( 'bxslider' ); elseif ( $filter ) wp_enqueue_script( 'isotope' ); return $out; }
while ( $blogPosts->have_posts() ) : $blogPosts->the_post(); $format = ( get_post_format() ) ? ( get_post_format() ) : ( 'standard' ); $addClass .= ( is_sticky() ) ? ( ' sticky-post' ) : ( '' ); $addClass .= ( $articleColumn ) ? ( ' column col-1' . $articleColumn ) : ( '' ); $classes = ( $even || $addClass ) ? ( ' class="' . $even . $addClass . '"' ) : ( '' ); ?> <article<?php echo $classes; ?>> <?php get_template_part( 'inc/formats/format', $format ); ?> </article> <?php $even = ( $even ) ? ( '' ) : ( 'even' ); endwhile; ?> </section> <!-- /list-articles --> <?php wm_pagination( $blogPosts ); ?> <?php } else { wm_not_found(); } wp_reset_query(); ?>