Advertisement
michaellevelup

Ascend Portfolio shortcode

May 13th, 2022
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 11.29 KB | None | 0 0
  1. function kad_portfolio_shortcode_new_function( $atts, $content) {
  2.     extract(shortcode_atts(array(
  3.         'orderby'       => 'menu_order',
  4.         'cat'           => '',
  5.         'order'         => '',
  6.         'offset'        => null,
  7.         'id'            => (rand(10,1000)),
  8.         'columns'       => '4',
  9.         'lightbox'      => 'false',
  10.         'height'        => '',
  11.         'width'         => '',
  12.         'isostyle'      => 'masonry',
  13.         'layout'        => 'normal',
  14.         'filter'        => 'false',
  15.         'excerpt'       => 'false',
  16.         'showtypes'     => 'true',
  17.         'items'         => '4'
  18. ), $atts));
  19.     if(!empty($order) ) {
  20.         $order = $order;
  21.     } else if($orderby == 'menu_order' || $orderby == "title") {
  22.         $order = 'ASC';
  23.     } else {
  24.         $order = 'DESC';
  25.     }
  26.     if(empty($cat)) {
  27.         $cat = '';
  28.         $portfolio_cat_ID = '';
  29.     } else {
  30.         $portfolio_cat = get_term_by ('slug',$cat,'portfolio-type' );
  31.         $portfolio_cat_ID = $portfolio_cat -> term_id;
  32.     }
  33.     if ($columns == '2') {
  34.         $itemsize = 'tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12';
  35.         $slidewidth = 560;
  36.         $slideheight = 560;
  37.     } else if ($columns == '1') {
  38.         $itemsize = 'tcol-md-12 tcol-sm-12 tcol-xs-12 tcol-ss-12';
  39.         $slidewidth = 560;
  40.         $slideheight = 560;
  41.     } else if ($columns == '3'){
  42.         $itemsize = 'tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12';
  43.         $slidewidth = 366;
  44.         $slideheight = 366;
  45.     } else if ($columns == '6'){
  46.         $itemsize = 'tcol-md-2 tcol-sm-3 tcol-xs-4 tcol-ss-6';
  47.         $slidewidth = 240;
  48.         $slideheight = 240;
  49.     } else if ($columns == '5'){
  50.         $itemsize = 'tcol-md-25 tcol-sm-3 tcol-xs-4 tcol-ss-6';
  51.         $slidewidth = 240;
  52.         $slideheight = 240;
  53.     } else {
  54.         $itemsize = 'tcol-md-3 tcol-sm-4 tcol-xs-6 tcol-ss-12';
  55.         $slidewidth = 270;
  56.         $slideheight = 270;
  57.     }
  58.     if(!empty($height) && $height == 'none') {
  59.         $slideheight = null;
  60.     } else if(!empty($height)) {
  61.         $slideheight = $height;
  62.     }
  63.     if(!empty($width)){
  64.         $slidewidth = $width;
  65.     }
  66.     if(!empty($layout) && $layout == 'mosaic'){
  67.         if ($columns == '3') {
  68.                       $itemsize_normal = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12 mosiac_item_normal'; $ximgsize_normal = 400;$yimgsize_normal = 400;
  69.                       $itemsize_wide = 'tcol-lg-8 tcol-md-8 tcol-sm-8 tcol-xs-12 tcol-ss-12 mosiac_item_wide'; $ximgsize_wide = 800;$yimgsize_wide = 400; $wide_string = '0,8,16,22,30';
  70.                       $itemsize_tall = 'tcol-lg-4 tcol-md-4 tcol-sm-4 tcol-xs-6 tcol-ss-12 mosiac_item_tall'; $ximgsize_tall = 400;$yimgsize_tall = 800; $tall_string = '5,12,14,27';
  71.                       $itemsize_large = 'tcol-lg-8 tcol-md-8 tcol-sm-8 tcol-xs-12 tcol-ss-12 mosiac_item_large'; $ximgsize_large = 800;$yimgsize_large = 800; $large_string = '3,9,19,24';
  72.             } else {
  73.                       $itemsize_normal = 'tcol-lg-3 tcol-md-3 tcol-sm-3 tcol-xs-6 tcol-ss-12 mosiac_item_normal'; $ximgsize_normal = 300;$yimgsize_normal = 300;
  74.                       $itemsize_wide = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12 mosiac_item_wide'; $ximgsize_wide = 600;$yimgsize_wide = 300; $wide_string = '0,9,16,21,30';
  75.                       $itemsize_tall = 'tcol-lg-3 tcol-md-3 tcol-sm-3 tcol-xs-6 tcol-ss-12 mosiac_item_tall'; $ximgsize_tall = 300;$yimgsize_tall = 600; $tall_string = '4,12,18,25';
  76.                       $itemsize_large = 'tcol-lg-6 tcol-md-6 tcol-sm-6 tcol-xs-12 tcol-ss-12 mosiac_item_large'; $ximgsize_large = 600;$yimgsize_large = 600; $large_string = '1,10,17,22';
  77.             }
  78.                     global $kt_portfolio_loop_mosaic;
  79.                     $kt_portfolio_loop_mosaic = array(
  80.                     'itemsize_normal' => $itemsize_normal,
  81.                     'ximgsize_normal' => $ximgsize_normal,
  82.                     'yimgsize_normal' => $yimgsize_normal,
  83.                     'itemsize_wide' => $itemsize_wide,
  84.                     'ximgsize_wide' => $ximgsize_wide,
  85.                     'yimgsize_wide' => $yimgsize_wide,
  86.                     'wide_string' => $wide_string,
  87.                     'itemsize_tall' => $itemsize_tall,
  88.                     'ximgsize_tall' => $ximgsize_tall,
  89.                     'yimgsize_tall' => $yimgsize_tall,
  90.                     'tall_string' => $tall_string,
  91.                     'itemsize_large' => $itemsize_large,
  92.                     'ximgsize_large' => $ximgsize_large,
  93.                     'yimgsize_large' => $yimgsize_large,
  94.                     'large_string' => $large_string,
  95.                     'item_count' => 0,
  96.                     );
  97.     }
  98.     global $ascend_premium, $kt_portfolio_loop;
  99.     if(isset($ascend_premium['ascend_animate_in']) && $ascend_premium['ascend_animate_in'] == 1) {
  100.         $animate = 1;
  101.     } else {
  102.         $animate = 0;
  103.     }
  104.                  $kt_portfolio_loop = array(
  105.                     'lightbox' => $lightbox,
  106.                     'showexcerpt' => $excerpt,
  107.                     'showtypes' => $showtypes,
  108.                     'slidewidth' => apply_filters('kt_portfolio_grid_image_width', $slidewidth),
  109.                     'slideheight' => apply_filters('kt_portfolio_grid_image_height', $slideheight),
  110.                     );
  111. ob_start(); ?>
  112.     <?php if ($filter == "true") { ?>
  113.         <section id="options" class="clearfix">
  114.             <?php global $ascend_premium;
  115.             if(!empty($ascend_premium['filter_all_text'])) {
  116.                 $alltext = $ascend_premium['filter_all_text'];
  117.             } else {
  118.                 $alltext = __('All', 'ascend');
  119.             }
  120.             if(!empty($ascend_premium['portfolio_filter_text'])) {
  121.                 $portfoliofiltertext = $ascend_premium['portfolio_filter_text'];
  122.             } else {
  123.                 $portfoliofiltertext = __('Filter Projects', 'ascend');
  124.             }
  125.             $termtypes = array( 'child_of' => $portfolio_cat_ID,);
  126.             $categories= get_terms('portfolio-type', $termtypes);
  127.             $count = count($categories);
  128.            
  129.                         echo '<a class="filter-trigger headerfont" data-toggle="collapse" data-target=".filter-collapse"><i class="icon-tags"></i> '.$portfoliofiltertext.'</a>';
  130.                         echo '<ul id="filters" class="clearfix option-set filter-collapse">';
  131.                         echo '<li class="postclass"><a href="#" data-filter="*" title="All" class="selected"><h5>'.$alltext.'</h5><div class="arrow-up"></div></a></li>';
  132.                         if ( $count > 0 ){
  133.                             foreach ($categories as $category){
  134.                                 $termname = strtolower($category->slug);
  135.                                 $termname = preg_replace("/[^a-zA-Z 0-9]+/", " ", $termname);
  136.                                 $termname = str_replace(' ', '-', $termname);
  137.                                     echo '<li class="postclass"><a href="#" data-filter=".'.esc_attr($termname).'" title="" rel="'.esc_attr($termname).'"><h5>'.$category->name.'</h5><div class="arrow-up"></div></a></li>';
  138.                                 }
  139.                         }
  140.                         echo "</ul>"; ?>
  141.             </section>
  142.             <?php }
  143.  
  144.             if(!empty($layout) && $layout == 'mosaic'){ ?>
  145.                  <div class="kad-mosaic-portfolio-wrapper">
  146.                  <div id="portfoliowrapper" class="init-mosaic-isotope reinit-isotope rowtight" data-fade-in="<?php echo esc_attr($animate);?>" data-iso-selector=".p-item" data-iso-style="packery" data-iso-filter="true">
  147.             <?php } else { ?>
  148.                 <div class="home-portfolio kad-portfolio-wrapper">
  149.                         <div id="portfoliowrapper-<?php echo esc_attr($id);?>" class="rowtight init-isotope-intrinsic reinit-isotope" data-fade-in="<?php echo esc_attr($animate);?>" data-iso-selector=".p-item" data-iso-style="<?php echo esc_attr($isostyle);?>" data-iso-filter="true">
  150.             <?php }            
  151.                 $wp_query = null;
  152.                   $wp_query = new WP_Query();
  153.                       if ( $orderby == 'date-title' ) {
  154.                           $wp_query->query(array(
  155.                             'orderby'           => array( 'date' => 'DESC', 'title' => 'ASC' ),                        
  156.                             'offset'            => $offset,
  157.                             'post_type'         => 'portfolio',
  158.                             'portfolio-type'    => $cat,
  159.                             'posts_per_page'    => $items
  160.                             )
  161.                           );                          
  162.                       } else {
  163.                       $wp_query->query(array(
  164.                         'orderby'           => $orderby,
  165.                         'order'             => $order,
  166.                         'offset'            => $offset,
  167.                         'post_type'         => 'portfolio',
  168.                         'portfolio-type'    => $cat,
  169.                         'posts_per_page'    => $items
  170.                         )
  171.                       );    
  172.                       }
  173.                     if ( $wp_query ) : while ( $wp_query->have_posts() ) : $wp_query->the_post();
  174.  
  175.                     if(!empty($layout) && $layout == 'mosaic'){
  176.                                 do_action('kadence_portfolio_loop_start');
  177.                                     get_template_part('templates/content', 'loop-portfolio-mosaic');
  178.                                   do_action('kadence_portfolio_loop_end');
  179.  
  180.                     } else {
  181.  
  182.                         global $post; $terms = get_the_terms( $post->ID, 'portfolio-type' );
  183.                         if ( $terms && ! is_wp_error( $terms ) ) :
  184.                             $links = array();
  185.                                 foreach ( $terms as $term ) { $links[] = $term->slug;}
  186.                             $links = preg_replace("/[^a-zA-Z 0-9]+/", " ", $links);
  187.                             $links = str_replace(' ', '-', $links);
  188.                             $tax = join( " ", $links );    
  189.                         else :  
  190.                             $tax = '';  
  191.                         endif;
  192.                         ?>
  193.                
  194.                         <div class="<?php echo esc_attr($itemsize);?> <?php echo strtolower($tax); ?> all p-item">
  195.                             <?php do_action('kadence_portfolio_loop_start');
  196.                                 get_template_part('templates/content', 'loop-portfolio');
  197.                                 do_action( 'kadence_portfolio_loop_end' );
  198.                             ?>
  199.                         </div>
  200.             <?php }
  201.  
  202.             endwhile; else: ?>
  203.                 <li class="error-not-found"><?php _e('Sorry, no portfolio entries found.', 'ascend');?></li>
  204.             <?php endif; ?>
  205.             </div> <!-- portfoliowrapper -->
  206.             <?php $wp_query = null; wp_reset_query(); ?>
  207.         </div><!-- /.home-portfolio -->
  208.  
  209.     <?php  $output = ob_get_contents();
  210.         ob_end_clean();
  211.         wp_reset_postdata();
  212.     return $output;
  213. }
  214.  
  215. add_action('wp', 'remove_ascend_portfolio_shortcode');
  216.  
  217. function remove_ascend_portfolio_shortcode(){
  218.     remove_shortcode('portfolio_posts');
  219.     add_shortcode('portfolio_posts', 'kad_portfolio_shortcode_new_function');
  220. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement