Advertisement
Guest User

My Post Slider

a guest
Nov 22nd, 2016
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 23.78 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Post/Page Content
  4.  *
  5.  * Element is in Beta and by default disabled. Todo: test with layerslider elements. currently throws error bc layerslider is only included if layerslider element is detected which is not the case with the post/page element
  6.  */
  7.  
  8. if ( !class_exists( 'my_avia_sc_postslider' ))
  9. {
  10.     class my_avia_sc_postslider extends aviaShortcodeTemplate
  11.     {
  12.  
  13.         /**
  14.          * Create the config array for the shortcode button
  15.          */
  16.         function shortcode_insert_button()
  17.         {
  18.             $this->config['name']       = __('My Post Slider', 'avia_framework' );
  19.             $this->config['tab']        = __('Content Elements', 'avia_framework' );
  20.             $this->config['icon']       = AviaBuilder::$path['imagesURL']."sc-postslider.png";
  21.             $this->config['order']      = 30;
  22.             $this->config['target']     = 'avia-target-insert';
  23.             $this->config['shortcode']  = 'my_av_postslider';
  24.             $this->config['tooltip']    = __('Display a modified Slideshow of Post Entries', 'avia_framework' );
  25.             $this->config['drag-level'] = 3;
  26.         }
  27.  
  28.         /**
  29.          * Popup Elements
  30.          *
  31.          * If this function is defined in a child class the element automatically gets an edit button, that, when pressed
  32.          * opens a modal window that allows to edit the element properties
  33.          *
  34.          * @return void
  35.          */
  36.         function popup_elements()
  37.         {
  38.             $this->elements = array(
  39.  
  40.                 array(
  41.                         "name"  => __("Which Entries?", 'avia_framework' ),
  42.                         "desc"  => __("Select which entries should be displayed by selecting a taxonomy", 'avia_framework' ),
  43.                         "id"    => "link",
  44.                         "fetchTMPL" => true,
  45.                         "type"  => "linkpicker",
  46.                         "subtype"  => array( __('Display Entries from:',  'avia_framework' )=>'taxonomy'),
  47.                         "multiple"  => 6,
  48.                         "std"   => "category"
  49.                 ),
  50.  
  51.                 array(
  52.                         "name"  => __("Columns", 'avia_framework' ),
  53.                         "desc"  => __("How many columns should be displayed?", 'avia_framework' ),
  54.                         "id"    => "columns",
  55.                         "type"  => "select",
  56.                         "std"   => "3",
  57.                         "subtype" => array( __('1 Columns', 'avia_framework' )=>'1',
  58.                                             __('2 Columns', 'avia_framework' )=>'2',
  59.                                             __('3 Columns', 'avia_framework' )=>'3',
  60.                                             __('4 Columns', 'avia_framework' )=>'4',
  61.                                             __('5 Columns', 'avia_framework' )=>'5',
  62.                                             )),
  63.                 array(
  64.                         "name"  => __("Entry Number", 'avia_framework' ),
  65.                         "desc"  => __("How many items should be displayed?", 'avia_framework' ),
  66.                         "id"    => "items",
  67.                         "type"  => "select",
  68.                         "std"   => "9",
  69.                         "subtype" => AviaHtmlHelper::number_array(1,100,1, array('All'=>'-1'))),
  70.  
  71.                 array(
  72.                     "name"  => __("Offset Number", 'avia_framework' ),
  73.                     "desc"  => __("The offset determines where the query begins pulling posts. Useful if you want to remove a certain number of posts because you already query them with another post slider element.", 'avia_framework' ),
  74.                     "id"    => "offset",
  75.                     "type"  => "select",
  76.                     "std"   => "0",
  77.                     "subtype" => AviaHtmlHelper::number_array(1,100,1, array(__('Deactivate offset','avia_framework')=>'0', __('Do not allow duplicate posts on the entire page (set offset automatically)', 'avia_framework' ) =>'no_duplicates'))),
  78.  
  79.                 array(
  80.                         "name"  => __("Title and Excerpt",'avia_framework' ),
  81.                         "desc"  => __("Choose if you want to only display the post title or title and excerpt",'avia_framework' ),
  82.                         "id"    => "contents",
  83.                         "type"  => "select",
  84.                         "std"   => "excerpt",
  85.                         "subtype" => array(
  86.                             __('Title and Excerpt',  'avia_framework' ) =>'excerpt',
  87.                             __('Title and Excerpt + Read More Link',  'avia_framework' ) =>'excerpt_read_more',
  88.                             __('Only Title',  'avia_framework' ) =>'title',
  89.                             __('Only Title + Read More Link',  'avia_framework' ) =>'title_read_more',
  90.                             __('Only excerpt',  'avia_framework' ) =>'only_excerpt',
  91.                             __('Only excerpt + Read More Link',  'avia_framework' ) =>'only_excerpt_read_more',
  92.                             __('No Title and no excerpt',  'avia_framework' ) =>'no')),
  93.  
  94.                 array(
  95.                             "name"  => __("Preview Image Size", 'avia_framework' ),
  96.                             "desc"  => __("Set the image size of the preview images", 'avia_framework' ),
  97.                             "id"    => "preview_mode",
  98.                             "type"  => "select",
  99.                             "std"   => "auto",
  100.                             "subtype" => array(__('Set the preview image size automatically based on column width','avia_framework' ) =>'auto',__('Choose the preview image size manually (select thumbnail size)','avia_framework' ) =>'custom')),
  101.  
  102.                 array(
  103.                             "name"  => __("Select custom preview image size", 'avia_framework' ),
  104.                             "desc"  => __("Choose image size for Preview Image", 'avia_framework' ),
  105.                             "id"    => "image_size",
  106.                             "type"  => "select",
  107.                             "required"  => array('preview_mode','equals','custom'),
  108.                             "std"   => "portfolio",
  109.                             "subtype" =>  AviaHelper::get_registered_image_sizes(array('logo'))
  110.                             ),
  111.                
  112.                 /*
  113. array(
  114.                             "name"  => __("Post Slider Transition", 'avia_framework' ),
  115.                             "desc"  => __("Choose the transition for your Post Slider.", 'avia_framework' ),
  116.                             "id"    => "animation",
  117.                             "type"  => "select",
  118.                             "std"   => "fade",
  119.                             "subtype" => array(__('Slide','avia_framework' ) =>'slide',__('Fade','avia_framework' ) =>'fade'),
  120.                             ),
  121. */
  122.                
  123.                
  124.                 array(
  125.                         "name"  => __("Autorotation active?",'avia_framework' ),
  126.                         "desc"  => __("Check if the slideshow should rotate by default",'avia_framework' ),
  127.                         "id"    => "autoplay",
  128.                         "type"  => "select",
  129.                         "std"   => "no",
  130.                         "subtype" => array(__('Yes','avia_framework' ) =>'yes',__('No','avia_framework' ) =>'no')),
  131.  
  132.                 array(
  133.                     "name"  => __("Slideshow autorotation duration",'avia_framework' ),
  134.                     "desc"  => __("Slideshow will rotate every X seconds",'avia_framework' ),
  135.                     "id"    => "interval",
  136.                     "type"  => "select",
  137.                     "std"   => "5",
  138.                     "required"  => array('autoplay','equals','yes'),
  139.                     "subtype" =>
  140.                     array('3'=>'3','4'=>'4','5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9','10'=>'10','15'=>'15','20'=>'20','30'=>'30','40'=>'40','60'=>'60','100'=>'100')),
  141.  
  142.  
  143.                 );
  144.  
  145.  
  146.                 if(current_theme_supports('add_avia_builder_post_type_option'))
  147.                 {
  148.                     $element = array(
  149.                         "name"  => __("Select Post Type", 'avia_framework' ),
  150.                         "desc"  => __("Select which post types should be used. Note that your taxonomy will be ignored if you do not select an assign post type.
  151.                                      If yo don't select post type all registered post types will be used", 'avia_framework' ),
  152.                         "id"    => "post_type",
  153.                         "type"  => "select",
  154.                         "multiple"  => 6,
  155.                         "std"   => "",
  156.                         "subtype" => AviaHtmlHelper::get_registered_post_type_array()
  157.                     );
  158.  
  159.                     array_unshift($this->elements, $element);
  160.                 }
  161.         }
  162.  
  163.         /**
  164.          * Editor Element - this function defines the visual appearance of an element on the AviaBuilder Canvas
  165.          * Most common usage is to define some markup in the $params['innerHtml'] which is then inserted into the drag and drop container
  166.          * Less often used: $params['data'] to add data attributes, $params['class'] to modify the className
  167.          *
  168.          *
  169.          * @param array $params this array holds the default values for $content and $args.
  170.          * @return $params the return array usually holds an innerHtml key that holds item specific markup.
  171.          */
  172.         function editor_element($params)
  173.         {
  174.             $params['innerHtml'] = "<img src='".$this->config['icon']."' title='".$this->config['name']."' />";
  175.             $params['innerHtml'].= "<div class='avia-element-label'>".$this->config['name']."</div>";
  176.             $params['content']   = NULL; //remove to allow content elements
  177.             return $params;
  178.         }
  179.  
  180.  
  181.  
  182.         /**
  183.          * Frontend Shortcode Handler
  184.          *
  185.          * @param array $atts array of attributes
  186.          * @param string $content text within enclosing form of shortcode element
  187.          * @param string $shortcodename the shortcode found, when == callback name
  188.          * @return string $output returns the modified html string
  189.          */
  190.         function shortcode_handler($atts, $content = "", $shortcodename = "", $meta = "")
  191.         {
  192.             if(isset($atts['link']))
  193.             {
  194.                 $atts['link'] = explode(',', $atts['link'], 2 );
  195.                 $atts['taxonomy'] = $atts['link'][0];
  196.  
  197.                 if(isset($atts['link'][1]))
  198.                 {
  199.                     $atts['categories'] = $atts['link'][1];
  200.                 }
  201.             }
  202.  
  203.             $atts['class'] = $meta['el_class'];
  204.  
  205.             $slider = new my_avia_post_slider($atts);
  206.             $slider->query_entries();
  207.             return $slider->html();
  208.         }
  209.  
  210.     }
  211. }
  212.  
  213.  
  214.  
  215.  
  216. if ( !class_exists( 'my_avia_post_slider' ) )
  217. {
  218.     class my_avia_post_slider
  219.     {  
  220.         static  $slide = 0;
  221.         protected $atts;
  222.         protected $entries;
  223.  
  224.         function __construct($atts = array())
  225.         {
  226.             $this->atts = shortcode_atts(array( 'type'      => 'slider', // can also be used as grid
  227.                                                 'style'     => '', //no_margin
  228.                                                 'columns'   => '4',
  229.                                                 'items'     => '16',
  230.                                                 'taxonomy'  => 'category',
  231.                                                 'post_type'=> get_post_types(),
  232.                                                 'contents'  => 'excerpt',
  233.                                                 'preview_mode' => 'auto',
  234.                                                 'image_size' => 'portfolio',
  235.                                                 'autoplay'  => 'no',
  236.                                                 'animation' => 'fade',
  237.                                                 'paginate'  => 'no',
  238.                                                 'use_main_query_pagination' => 'no',
  239.                                                 'interval'  => 5,
  240.                                                 'class'     => '',
  241.                                                 'categories'=> array(),
  242.                                                 'custom_query'=> array(),
  243.                                                 'offset' => 0,
  244.                                                 'custom_markup' => ''
  245.                                                 ), $atts, 'my_av_postslider');
  246.         }
  247.  
  248.         public function html()
  249.         {
  250.             global $avia_config;
  251.  
  252.             $output = "";
  253.  
  254.             if(empty($this->entries) || empty($this->entries->posts)) return $output;
  255.  
  256.             my_avia_post_slider::$slide ++;
  257.             extract($this->atts);
  258.  
  259.             if($preview_mode == 'auto') $image_size = 'portfolio';
  260.             $extraClass         = 'first';
  261.             $grid               = 'one_third';
  262.             $post_loop_count    = 1;
  263.             $loop_counter       = 1;
  264.             $autoplay           = $autoplay == "no" ? false : true;
  265.             $total              = $columns % 2 ? "odd" : "even";
  266.             $blogstyle          = function_exists('avia_get_option') ? avia_get_option('blog_global_style','') : "";
  267.             $excerpt_length     = 60;
  268.            
  269.            
  270.             if($blogstyle !== "")
  271.             {
  272.                 $excerpt_length = 240;
  273.             }
  274.            
  275.             switch($columns)
  276.             {
  277.                 case "1": $grid = 'av_fullwidth';  if($preview_mode == 'auto') $image_size = 'large'; break;
  278.                 case "2": $grid = 'av_one_half';   break;
  279.                 case "3": $grid = 'av_one_third';  break;
  280.                 case "4": $grid = 'av_one_fourth'; if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  281.                 case "5": $grid = 'av_one_fifth';  if($preview_mode == 'auto') $image_size = 'portfolio_small'; break;
  282.             }
  283.  
  284.  
  285.             $data = AviaHelper::create_data_string(array('autoplay'=>$autoplay, 'interval'=>$interval, 'animation' => $animation, 'show_slide_delay'=>90));
  286.  
  287.             $thumb_fallback = "";
  288.             $markup = avia_markup_helper(array('context' => 'blog','echo'=>false, 'custom_markup'=>$custom_markup));
  289.             $output .= "<div {$data} class='avia-content-slider avia-content-{$type}-active avia-content-slider".my_avia_post_slider::$slide." avia-content-slider-{$total} {$class}' $markup>";
  290.             $output .=      "<div class='avia-content-slider-inner'>";
  291.  
  292.                 foreach ($this->entries->posts as $entry)
  293.                 {
  294.                     $the_id     = $entry->ID;
  295.                     $parity     = $loop_counter % 2 ? 'odd' : 'even';
  296.                     $last       = $this->entries->post_count == $post_loop_count ? " post-entry-last " : "";
  297.                     $post_class = "post-entry post-entry-{$the_id} slide-entry-overview slide-loop-{$post_loop_count} slide-parity-{$parity} {$last}";
  298.                     $link       = get_permalink($the_id);
  299.                     $excerpt    = "";
  300.                     $title      = '';
  301.                     $show_meta  = !is_post_type_hierarchical($entry->post_type);
  302.                     $commentCount = get_comments_number($the_id);
  303.                     $thumbnail  = get_the_post_thumbnail( $the_id, $image_size );
  304.                     $format     = get_post_format( $the_id );
  305.                     if(empty($format)) $format = "standard";
  306.  
  307.                     if($thumbnail)
  308.                     {
  309.                         $thumb_fallback = $thumbnail;
  310.                         $thumb_class    = "real-thumbnail";
  311.                     }
  312.                     else
  313.                     {
  314.                         $thumbnail = "<span class=' fallback-post-type-icon' ".av_icon_string($format)."></span><span class='slider-fallback-image'>{{thumbnail}}</span>";
  315.                         $thumb_class    = "fake-thumbnail";
  316.                     }
  317.  
  318.  
  319.                     $permalink = '<div class="read-more-link"><a href="'.get_permalink($the_id).'" class="more-link">'.__('Read more','avia_framework').'<span class="more-link-arrow">  &rarr;</span></a></div>';
  320.                     $prepare_excerpt = !empty($entry->post_excerpt) ? $entry->post_excerpt : avia_backend_truncate($entry->post_content, apply_filters( 'avf_postgrid_excerpt_length' , $excerpt_length) , apply_filters( 'avf_postgrid_excerpt_delimiter' , " "), "…", true, '');
  321.  
  322.                             if($format == 'link')
  323.                             {
  324.                                     $current_post = array();
  325.                                     $current_post['content'] = $entry->post_content;
  326.                                     $current_post['title'] =  $entry->post_title;
  327.                                    
  328.                                     if(function_exists('avia_link_content_filter'))
  329.                                     {
  330.                                         $current_post = avia_link_content_filter($current_post);
  331.                                     }
  332.            
  333.                                     $link = $current_post['url'];
  334.                                 }
  335.                            
  336.                    
  337.                     switch($contents)
  338.                     {
  339.                         case "excerpt":
  340.                                 $excerpt = $prepare_excerpt;
  341.                                 $title = $entry->post_title;
  342.                                 break;
  343.                         case "excerpt_read_more":
  344.                                 $excerpt = $prepare_excerpt;
  345.                                 $excerpt .= $permalink;
  346.                                 $title = $entry->post_title;
  347.                                 break;
  348.                         case "title":
  349.                                 $excerpt = '';
  350.                                 $title = $entry->post_title;
  351.                                 break;
  352.                         case "title_read_more":
  353.                                 $excerpt = $permalink;
  354.                                 $title = $entry->post_title;
  355.                                 break;
  356.                         case "only_excerpt":
  357.                                 $excerpt = $prepare_excerpt;
  358.                                 $title = '';
  359.                                 break;
  360.                         case "only_excerpt_read_more":
  361.                                 $excerpt = $prepare_excerpt;
  362.                                 $excerpt .= $permalink;
  363.                                 $title = '';
  364.                                 break;
  365.                         case "no":
  366.                                 $excerpt = '';
  367.                                 $title = '';
  368.                                 break;
  369.                     }
  370.                    
  371.                     $title = apply_filters( 'avf_postslider_title', $title, $entry );
  372.                    
  373.                     if($loop_counter == 1) $output .= "<div class='slide-entry-wrap'>";
  374.                    
  375.                     $post_format = get_post_format($the_id) ? get_post_format($the_id) : 'standard';
  376.                    
  377.                     $markup = avia_markup_helper(array('context' => 'entry','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  378.                     $output .= "<article class='slide-entry flex_column {$style} {$post_class} {$grid} {$extraClass} {$thumb_class}' $markup>";
  379.                     $output .= $thumbnail ? "<a href='{$link}' data-rel='slide-".my_avia_post_slider::$slide."' class='slide-image' title=''>{$thumbnail}</a>" : "";
  380.                    
  381.                     if($post_format == "audio")
  382.                     {  
  383.                         $current_post = array();
  384.                         $current_post['content'] = $entry->post_content;
  385.                         $current_post['title'] =  $entry->post_title;
  386.                        
  387.                         $current_post = apply_filters( 'post-format-'.$post_format, $current_post );
  388.                        
  389.                         if(!empty( $current_post['before_content'] )) $output .= '<div class="big-preview single-big audio-preview">'.$current_post['before_content'].'</div>';
  390.                     }
  391.                    
  392.                     $output .= "<div class='slide-content'>";
  393.  
  394.                     $markup = avia_markup_helper(array('context' => 'entry_title','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  395.                     $output .= '<header class="entry-content-header">';
  396.                    
  397.                     if (!empty($title))
  398.                     {
  399.                         if($show_meta)
  400.                         {
  401.                             $taxonomies  = get_object_taxonomies(get_post_type($the_id));
  402.                             $cats = '';
  403.                             $excluded_taxonomies = array_merge( get_taxonomies( array( 'public' => false ) ), array('post_tag','post_format') );
  404.                             $excluded_taxonomies = apply_filters('avf_exclude_taxonomies', $excluded_taxonomies, get_post_type($the_id), $the_id);
  405.            
  406.                             if(!empty($taxonomies))
  407.                             {
  408.                                 foreach($taxonomies as $taxonomy)
  409.                                 {
  410.                                     if(!in_array($taxonomy, $excluded_taxonomies))
  411.                                     {
  412.                                         $cats .= get_the_term_list($the_id, $taxonomy, '', ', ','').' ';
  413.                                     }
  414.                                 }
  415.                             }
  416.                            
  417.                             /* MODIFICATION
  418.                             if(!empty($cats))
  419.                             {
  420.                                 $output .= '<span class="blog-categories minor-meta">';
  421.                                 $output .= $cats;
  422.                                 $output .= '</span>';
  423.                             }
  424.                             */
  425.                         }
  426.                        
  427.                         /* MODIFICATION                        
  428.                         $output .=  "<h3 class='slide-entry-title entry-title' $markup><a href='{$link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></h3>";
  429.                         */
  430.                         $output .=  "<p class='titre-post' $markup><a href='{$link}' title='".esc_attr(strip_tags($title))."'>".$title."</a></p>";
  431.  
  432.                         /* MODIFICATION
  433.                         $output .= '<span class="av-vertical-delimiter"></span>';
  434.                         */
  435.                     }
  436.                    
  437.                     $output .= '</header>';
  438.  
  439.                     if($show_meta && !empty($excerpt))
  440.                     {
  441.                         $meta  = "<div class='slide-meta'>";
  442.                         if ( $commentCount != "0" || comments_open($the_id) && $entry->post_type != 'portfolio')
  443.                         {
  444.                             $link_add = $commentCount === "0" ? "#respond" : "#comments";
  445.                             $text_add = $commentCount === "1" ? __('Comment', 'avia_framework' ) : __('Comments', 'avia_framework' );
  446.  
  447.                             $meta .= "<div class='slide-meta-comments'><a href='{$link}{$link_add}'>{$commentCount} {$text_add}</a></div><div class='slide-meta-del'>/</div>";
  448.                         }
  449.                         $markup = avia_markup_helper(array('context' => 'entry_time','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  450.                         $meta .= "<time class='slide-meta-time updated' $markup>" .get_the_time(get_option('date_format'), $the_id)."</time>";
  451.                         $meta .= "</div>";
  452.                        
  453.                         if($blogstyle !== "elegant-blog")
  454.                         {
  455.                             $output .= $meta;
  456.                             $meta = "";
  457.                         }
  458.                     }
  459.                     $markup = avia_markup_helper(array('context' => 'entry_content','echo'=>false, 'id'=>$the_id, 'custom_markup'=>$custom_markup));
  460.                     $excerpt = apply_filters( 'avf_post_slider_entry_excerpt', $excerpt, $prepare_excerpt, $permalink, $entry );
  461.                     $output .= !empty($excerpt) ? "<div class='slide-entry-excerpt entry-content' $markup>".$excerpt."</div>" : "";
  462.  
  463.                     $output .= "</div>";
  464.                    
  465.                     /* MODIFICATION
  466.                     $output .= '<footer class="entry-footer">';
  467.                     if( !empty($meta) ) $output .= $meta;
  468.                     $output .= '</footer>';
  469.                     */
  470.                    
  471.                     $output .= av_blog_entry_markup_helper( $the_id );
  472.                    
  473.                     $output .= "</article>";
  474.  
  475.                     $loop_counter ++;
  476.                     $post_loop_count ++;
  477.                     $extraClass = "";
  478.  
  479.                     if($loop_counter > $columns)
  480.                     {
  481.                         $loop_counter = 1;
  482.                         $extraClass = 'first';
  483.                     }
  484.  
  485.                     if($loop_counter == 1 || !empty($last))
  486.                     {
  487.                         $output .="</div>";
  488.                     }
  489.                 }
  490.  
  491.             $output .=      "</div>";
  492.  
  493.             if($post_loop_count -1 > $columns && $type == 'slider')
  494.             {
  495.                 $output .= $this->slide_navigation_arrows();
  496.             }
  497.            
  498.             global $wp_query;
  499.             if($use_main_query_pagination == 'yes' && $paginate == "yes")
  500.             {
  501.                 $avia_pagination = avia_pagination($wp_query->max_num_pages, 'nav');
  502.             }
  503.             else if($paginate == "yes")
  504.             {
  505.                 $avia_pagination = avia_pagination($this->entries, 'nav');
  506.             }
  507.  
  508.             if(!empty($avia_pagination)) $output .= "<div class='pagination-wrap pagination-slider'>{$avia_pagination}</div>";
  509.  
  510.  
  511.             $output .= "</div>";
  512.  
  513.             $output = str_replace('{{thumbnail}}', $thumb_fallback, $output);
  514.  
  515.             wp_reset_query();
  516.             return $output;
  517.         }
  518.  
  519.         protected function slide_navigation_arrows()
  520.         {
  521.             $html  = "";
  522.             $html .= "<div class='avia-slideshow-arrows avia-slideshow-controls'>";
  523.             $html .=    "<a href='#prev' class='prev-slide' ".av_icon_string('prev_big').">".__('Previous','avia_framework' )."</a>";
  524.             $html .=    "<a href='#next' class='next-slide' ".av_icon_string('next_big').">".__('Next','avia_framework' )."</a>";
  525.             $html .= "</div>";
  526.  
  527.             return $html;
  528.         }
  529.  
  530.         //fetch new entries
  531.         public function query_entries($params = array())
  532.         {  
  533.             global $avia_config;
  534.  
  535.             if(empty($params)) $params = $this->atts;
  536.  
  537.             if(empty($params['custom_query']))
  538.             {
  539.                 $query = array();
  540.  
  541.                 if(!empty($params['categories']))
  542.                 {
  543.                     //get the portfolio categories
  544.                     $terms  = explode(',', $params['categories']);
  545.                 }
  546.  
  547.                 $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : get_query_var( 'page' );
  548.                 if(!$page || $params['paginate'] == 'no') $page = 1;
  549.  
  550.                 //if we find no terms for the taxonomy fetch all taxonomy terms
  551.                 if(empty($terms[0]) || is_null($terms[0]) || $terms[0] === "null")
  552.                 {
  553.                     $terms = array();
  554.                     $allTax = get_terms( $params['taxonomy']);
  555.                     foreach($allTax as $tax)
  556.                     {
  557.                         $terms[] = $tax->term_id;
  558.                     }
  559.  
  560.                 }
  561.  
  562.                 if($params['offset'] == 'no_duplicates')
  563.                 {
  564.                     $params['offset'] = false;
  565.                     $no_duplicates = true;
  566.                 }
  567.                
  568.                
  569.                 //wordpress 4.4 offset fix
  570.                 if( $params['offset'] == 0 )
  571.                 {
  572.                     $params['offset'] = false;
  573.                 }
  574.                 else
  575.                 {  
  576.                     //if the offset is set the paged param is ignored. therefore we need to factor in the page number
  577.                     $params['offset'] = $params['offset'] + ( ($page -1 ) * $params['items']);
  578.                 }
  579.                
  580.                
  581.  
  582.                 if(empty($params['post_type'])) $params['post_type'] = get_post_types();
  583.                 if(is_string($params['post_type'])) $params['post_type'] = explode(',', $params['post_type']);
  584.  
  585.                 $query = array( 'orderby'   => 'date',
  586.                                 'order'     => 'DESC',
  587.                                 'paged'     => $page,
  588.                                 'post_type' => $params['post_type'],
  589.                                 'posts_per_page' => $params['items'],
  590.                                 'offset' => $params['offset'],
  591.                                 'post__not_in' => (!empty($no_duplicates)) ? $avia_config['posts_on_current_page'] : array(),
  592.                                 'tax_query' => array(   array(  'taxonomy'  => $params['taxonomy'],
  593.                                                                 'field'     => 'id',
  594.                                                                 'terms'     => $terms,
  595.                                                                 'operator'  => 'IN')));
  596.                                                                
  597.             }
  598.             else
  599.             {
  600.                 $query = $params['custom_query'];
  601.             }
  602.  
  603.  
  604.             $query = apply_filters('avia_post_slide_query', $query, $params);
  605.  
  606.             @$this->entries = new WP_Query( $query ); //@ is used to prevent errors caused by wpml
  607.  
  608.             // store the queried post ids in
  609.             if( $this->entries->have_posts() )
  610.             {
  611.                 while( $this->entries->have_posts() )
  612.                 {
  613.                     $this->entries->the_post();
  614.                     $avia_config['posts_on_current_page'][] = get_the_ID();
  615.                 }
  616.             }
  617.  
  618.         }
  619.     }
  620. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement