parkeast

Random Order in Extra Portfolio

Mar 2nd, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 12.89 KB | None | 0 0
  1. <?php
  2. class WPC_ET_Builder_Module_Portfolio extends ET_Builder_Module {
  3.     function init() {
  4.         $this->name = esc_html__( 'Portfolio', 'et_builder' );
  5.         $this->slug = 'et_pb_portfolio';
  6.         $this->whitelisted_fields = array(
  7.             'fullwidth',
  8.             'posts_number',
  9.             'include_categories',
  10.             'show_title',
  11.             'show_categories',
  12.             'show_pagination',
  13.             'background_layout',
  14.             'admin_label',
  15.             'module_id',
  16.             'module_class',
  17.             'zoom_icon_color',
  18.             'hover_overlay_color',
  19.             'hover_icon',
  20.         );
  21.         $this->fields_defaults = array(
  22.             'fullwidth'         => array( 'on' ),
  23.             'posts_number'      => array( 10, 'add_default_setting' ),
  24.             'show_title'        => array( 'on' ),
  25.             'show_categories'   => array( 'on' ),
  26.             'show_pagination'   => array( 'on' ),
  27.             'background_layout' => array( 'light' ),
  28.         );
  29.         $this->main_css_element = '%%order_class%% .et_pb_portfolio_item';
  30.         $this->advanced_options = array(
  31.             'fonts' => array(
  32.                 'title'   => array(
  33.                     'label'    => esc_html__( 'Title', 'et_builder' ),
  34.                     'css'      => array(
  35.                         'main' => "{$this->main_css_element} h2",
  36.                         'important' => 'all',
  37.                     ),
  38.                 ),
  39.                 'caption' => array(
  40.                     'label'    => esc_html__( 'Meta', 'et_builder' ),
  41.                     'css'      => array(
  42.                         'main' => "{$this->main_css_element} .post-meta, {$this->main_css_element} .post-meta a",
  43.                     ),
  44.                 ),
  45.             ),
  46.             'background' => array(
  47.                 'settings' => array(
  48.                     'color' => 'alpha',
  49.                 ),
  50.             ),
  51.             'border' => array(),
  52.         );
  53.         $this->custom_css_options = array(
  54.             'portfolio_image' => array(
  55.                 'label'    => esc_html__( 'Portfolio Image', 'et_builder' ),
  56.                 'selector' => '.et_portfolio_image',
  57.             ),
  58.             'overlay' => array(
  59.                 'label'    => esc_html__( 'Overlay', 'et_builder' ),
  60.                 'selector' => '.et_overlay',
  61.             ),
  62.             'overlay_icon' => array(
  63.                 'label'    => esc_html__( 'Overlay Icon', 'et_builder' ),
  64.                 'selector' => '.et_overlay:before',
  65.             ),
  66.             'portfolio_title' => array(
  67.                 'label'    => esc_html__( 'Portfolio Title', 'et_builder' ),
  68.                 'selector' => '.et_pb_portfolio_item h2',
  69.             ),
  70.             'portfolio_post_meta' => array(
  71.                 'label'    => esc_html__( 'Portfolio Post Meta', 'et_builder' ),
  72.                 'selector' => '.et_pb_portfolio_item .post-meta',
  73.             ),
  74.         );
  75.     }
  76.     function get_fields() {
  77.         $fields = array(
  78.             'fullwidth' => array(
  79.                 'label'           => esc_html__( 'Layout', 'et_builder' ),
  80.                 'type'            => 'select',
  81.                 'option_category' => 'layout',
  82.                 'options'         => array(
  83.                     'on'  => esc_html__( 'Fullwidth', 'et_builder' ),
  84.                     'off' => esc_html__( 'Grid', 'et_builder' ),
  85.                 ),
  86.                 'description'       => esc_html__( 'Choose your desired portfolio layout style.', 'et_builder' ),
  87.             ),
  88.             'posts_number' => array(
  89.                 'label'             => esc_html__( 'Posts Number', 'et_builder' ),
  90.                 'type'              => 'text',
  91.                 'option_category'   => 'configuration',
  92.                 'description'       => esc_html__( 'Define the number of projects that should be displayed per page.', 'et_builder' ),
  93.             ),
  94.             'include_categories' => array(
  95.                 'label'            => esc_html__( 'Include Categories', 'et_builder' ),
  96.                 'renderer'         => 'et_builder_include_categories_option',
  97.                 'option_category'  => 'basic_option',
  98.                 'description'      => esc_html__( 'Select the categories that you would like to include in the feed.', 'et_builder' ),
  99.             ),
  100.             'show_title' => array(
  101.                 'label'           => esc_html__( 'Show Title', 'et_builder' ),
  102.                 'type'            => 'yes_no_button',
  103.                 'option_category' => 'configuration',
  104.                 'options'         => array(
  105.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  106.                     'off' => esc_html__( 'No', 'et_builder' ),
  107.                 ),
  108.                 'description'       => esc_html__( 'Turn project titles on or off.', 'et_builder' ),
  109.             ),
  110.             'show_categories' => array(
  111.                 'label'           => esc_html__( 'Show Categories', 'et_builder' ),
  112.                 'type'            => 'yes_no_button',
  113.                 'option_category' => 'configuration',
  114.                 'options'         => array(
  115.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  116.                     'off' => esc_html__( 'No', 'et_builder' ),
  117.                 ),
  118.                 'description'        => esc_html__( 'Turn the category links on or off.', 'et_builder' ),
  119.             ),
  120.             'show_pagination' => array(
  121.                 'label'           => esc_html__( 'Show Pagination', 'et_builder' ),
  122.                 'type'            => 'yes_no_button',
  123.                 'option_category' => 'configuration',
  124.                 'options'         => array(
  125.                     'on'  => esc_html__( 'Yes', 'et_builder' ),
  126.                     'off' => esc_html__( 'No', 'et_builder' ),
  127.                 ),
  128.                 'description'        => esc_html__( 'Enable or disable pagination for this feed.', 'et_builder' ),
  129.             ),
  130.             'background_layout' => array(
  131.                 'label'           => esc_html__( 'Text Color', 'et_builder' ),
  132.                 'type'            => 'select',
  133.                 'option_category' => 'color_option',
  134.                 'options'         => array(
  135.                     'light'  => esc_html__( 'Dark', 'et_builder' ),
  136.                     'dark' => esc_html__( 'Light', 'et_builder' ),
  137.                 ),
  138.                 'description'        => esc_html__( 'Here you can choose whether your text should be light or dark. If you are working with a dark background, then your text should be light. If your background is light, then your text should be set to dark.', 'et_builder' ),
  139.             ),
  140.             'zoom_icon_color' => array(
  141.                 'label'             => esc_html__( 'Zoom Icon Color', 'et_builder' ),
  142.                 'type'              => 'color',
  143.                 'custom_color'      => true,
  144.                 'tab_slug'          => 'advanced',
  145.             ),
  146.             'hover_overlay_color' => array(
  147.                 'label'             => esc_html__( 'Hover Overlay Color', 'et_builder' ),
  148.                 'type'              => 'color-alpha',
  149.                 'custom_color'      => true,
  150.                 'tab_slug'          => 'advanced',
  151.             ),
  152.             'hover_icon' => array(
  153.                 'label'               => esc_html__( 'Hover Icon Picker', 'et_builder' ),
  154.                 'type'                => 'text',
  155.                 'option_category'     => 'configuration',
  156.                 'class'               => array( 'et-pb-font-icon' ),
  157.                 'renderer'            => 'et_pb_get_font_icon_list',
  158.                 'renderer_with_field' => true,
  159.                 'tab_slug'            => 'advanced',
  160.             ),
  161.             'disabled_on' => array(
  162.                 'label'           => esc_html__( 'Disable on', 'et_builder' ),
  163.                 'type'            => 'multiple_checkboxes',
  164.                 'options'         => array(
  165.                     'phone'   => esc_html__( 'Phone', 'et_builder' ),
  166.                     'tablet'  => esc_html__( 'Tablet', 'et_builder' ),
  167.                     'desktop' => esc_html__( 'Desktop', 'et_builder' ),
  168.                 ),
  169.                 'additional_att'  => 'disable_on',
  170.                 'option_category' => 'configuration',
  171.                 'description'     => esc_html__( 'This will disable the module on selected devices', 'et_builder' ),
  172.             ),
  173.             'admin_label' => array(
  174.                 'label'       => esc_html__( 'Admin Label', 'et_builder' ),
  175.                 'type'        => 'text',
  176.                 'description' => esc_html__( 'This will change the label of the module in the builder for easy identification.', 'et_builder' ),
  177.             ),
  178.             'module_id' => array(
  179.                 'label'           => esc_html__( 'CSS ID', 'et_builder' ),
  180.                 'type'            => 'text',
  181.                 'option_category' => 'configuration',
  182.                 'tab_slug'        => 'custom_css',
  183.                 'option_class'    => 'et_pb_custom_css_regular',
  184.             ),
  185.             'module_class' => array(
  186.                 'label'           => esc_html__( 'CSS Class', 'et_builder' ),
  187.                 'type'            => 'text',
  188.                 'option_category' => 'configuration',
  189.                 'tab_slug'        => 'custom_css',
  190.                 'option_class'    => 'et_pb_custom_css_regular',
  191.             ),
  192.         );
  193.         return $fields;
  194.     }
  195.     function shortcode_callback( $atts, $content = null, $function_name ) {
  196.         $module_id          = $this->shortcode_atts['module_id'];
  197.         $module_class       = $this->shortcode_atts['module_class'];
  198.         $fullwidth          = $this->shortcode_atts['fullwidth'];
  199.         $posts_number       = $this->shortcode_atts['posts_number'];
  200.         $include_categories = $this->shortcode_atts['include_categories'];
  201.         $show_title         = $this->shortcode_atts['show_title'];
  202.         $show_categories    = $this->shortcode_atts['show_categories'];
  203.         $show_pagination    = $this->shortcode_atts['show_pagination'];
  204.         $background_layout  = $this->shortcode_atts['background_layout'];
  205.         $zoom_icon_color     = $this->shortcode_atts['zoom_icon_color'];
  206.         $hover_overlay_color = $this->shortcode_atts['hover_overlay_color'];
  207.         $hover_icon          = $this->shortcode_atts['hover_icon'];
  208.         $admin_label          = $this->shortcode_atts['admin_label'];
  209.         global $paged;
  210.         $module_class = ET_Builder_Element::add_module_order_class( $module_class, $function_name );
  211.         if ( '' !== $zoom_icon_color ) {
  212.             ET_Builder_Element::set_style( $function_name, array(
  213.                 'selector'    => '%%order_class%% .et_overlay:before',
  214.                 'declaration' => sprintf(
  215.                     'color: %1$s !important;',
  216.                     esc_html( $zoom_icon_color )
  217.                 ),
  218.             ) );
  219.         }
  220.         if ( '' !== $hover_overlay_color ) {
  221.             ET_Builder_Element::set_style( $function_name, array(
  222.                 'selector'    => '%%order_class%% .et_overlay',
  223.                 'declaration' => sprintf(
  224.                     'background-color: %1$s;
  225.                     border-color: %1$s;',
  226.                     esc_html( $hover_overlay_color )
  227.                 ),
  228.             ) );
  229.         }
  230.         $container_is_closed = false;
  231.         $args = array(
  232.             'posts_per_page' => (int) $posts_number,
  233.             'post_type'      => 'project',
  234. //          'order'    => 'ASC',
  235.             'orderby'  => 'rand'
  236.         );
  237.         $et_paged = is_front_page() ? get_query_var( 'page' ) : get_query_var( 'paged' );
  238.         if ( is_front_page() ) {
  239.             $paged = $et_paged;
  240.         }
  241.         if ( '' !== $include_categories )
  242.             $args['tax_query'] = array(
  243.                 array(
  244.                     'taxonomy' => 'project_category',
  245.                     'field' => 'id',
  246.                     'terms' => explode( ',', $include_categories ),
  247.                     'operator' => 'IN',
  248.                 )
  249.             );
  250.         if ( ! is_search() ) {
  251.             $args['paged'] = $et_paged;
  252.         }
  253.         $main_post_class = sprintf(
  254.             'et_pb_portfolio_item%1$s',
  255.             ( 'on' !== $fullwidth ? ' et_pb_grid_item' : '' )
  256.         );
  257.         ob_start();
  258.         query_posts( $args );
  259.         if ( have_posts() ) {
  260.             while ( have_posts() ) {
  261.                 the_post(); ?>
  262.  
  263.                 <div id="post-<?php the_ID(); ?>" <?php post_class( $main_post_class ); ?>>
  264.  
  265.             <?php
  266.                 $thumb = '';
  267.                 $width = 'on' === $fullwidth ?  1080 : 400;
  268.                 $width = (int) apply_filters( 'et_pb_portfolio_image_width', $width );
  269.                 $height = 'on' === $fullwidth ?  9999 : 284;
  270.                 $height = (int) apply_filters( 'et_pb_portfolio_image_height', $height );
  271.                 $classtext = 'on' === $fullwidth ? 'et_pb_post_main_image' : '';
  272.                 $titletext = get_the_title();
  273.                 $thumbnail = get_thumbnail( $width, $height, $classtext, $titletext, $titletext, false, 'Blogimage' );
  274.                 $thumb = $thumbnail["thumb"];
  275.                 if ( '' !== $thumb ) : ?>
  276.                     <?php if ( 'on' === $show_categories ) : ?>
  277.                     <a href="<?php echo $admin_label ?>">
  278.                     <?php else: ?>
  279.                     <a href="<?php esc_url( the_permalink() ); ?>">
  280.                     <?php endif; ?>
  281.                     <?php if ( 'on' !== $fullwidth ) : ?>
  282.                         <span class="et_portfolio_image">
  283.                     <?php endif; ?>
  284.                             <?php print_thumbnail( $thumb, $thumbnail["use_timthumb"], $titletext, $width, $height ); ?>
  285.                     <?php if ( 'on' !== $fullwidth ) :
  286.                             $data_icon = '' !== $hover_icon
  287.                                 ? sprintf(
  288.                                     ' data-icon="%1$s"',
  289.                                     esc_attr( et_pb_process_font_icon( $hover_icon ) )
  290.                                 )
  291.                                 : '';
  292.                             printf( '<span class="et_overlay%1$s"%2$s></span>',
  293.                                 ( '' !== $hover_icon ? ' et_pb_inline_icon' : '' ),
  294.                                 $data_icon
  295.                             );
  296.                     ?>
  297.                         </span>
  298.                     <?php endif; ?>
  299.                     </a>                   
  300.             <?php
  301.                 endif;
  302.             ?>
  303.                 <?php if ( 'on' === $show_title ) : ?>
  304.                     <h2><a href="<?php esc_url( the_permalink() ); ?>"><?php the_title(); ?></a></h2>
  305.                 <?php endif; ?>
  306.                 <?php if ( 'on' === $show_categories ) : ?>
  307.                     <h2><a href="<?php echo $admin_label ?>"><?php echo get_the_term_list( get_the_ID(), 'project_category', '', ', ' ); ?></a></h2>
  308.                 <?php endif; ?>
  309.  
  310.                 </div> <!-- .et_pb_portfolio_item -->
  311.     <?php   }
  312.             if ( 'on' === $show_pagination && ! is_search() ) {
  313.                 echo '</div> <!-- .et_pb_portfolio -->';
  314.                 $container_is_closed = true;
  315.                 if ( function_exists( 'wp_pagenavi' ) ) {
  316.                     wp_pagenavi();
  317.                 } else {
  318.                     if ( et_is_builder_plugin_active() ) {
  319.                         include( ET_BUILDER_PLUGIN_DIR . 'includes/navigation.php' );
  320.                     } else {
  321.                         get_template_part( 'includes/navigation', 'index' );
  322.                     }
  323.                 }
  324.             }
  325.             wp_reset_query();
  326.         } else {
  327.             if ( et_is_builder_plugin_active() ) {
  328.                 include( ET_BUILDER_PLUGIN_DIR . 'includes/no-results.php' );
  329.             } else {
  330.                 get_template_part( 'includes/no-results', 'index' );
  331.             }
  332.         }
  333.         $posts = ob_get_contents();
  334.         ob_end_clean();
  335.         $class = " et_pb_module et_pb_bg_layout_{$background_layout}";
  336.         $output = sprintf(
  337.             '<div%5$s class="%1$s%3$s%6$s">
  338.                 %2$s
  339.             %4$s',
  340.             ( 'on' === $fullwidth ? 'et_pb_portfolio' : 'et_pb_portfolio_grid clearfix' ),
  341.             $posts,
  342.             esc_attr( $class ),
  343.             ( ! $container_is_closed ? '</div> <!-- .et_pb_portfolio -->' : '' ),
  344.             ( '' !== $module_id ? sprintf( ' id="%1$s"', esc_attr( $module_id ) ) : '' ),
  345.             ( '' !== $module_class ? sprintf( ' %1$s', esc_attr( $module_class ) ) : '' )
  346.         );
  347.         return $output;
  348.     }
  349. }
Add Comment
Please, Sign In to add comment