<?php
namespace ElementorPro\Modules\Posts\Widgets;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Image_Size;
use Elementor\Group_Control_Typography;
use ElementorPro\Base\Base_Widget;
use ElementorPro\Core\Utils;
use ElementorPro\Modules\QueryControl\Module as Module_Query;
use ElementorPro\Modules\QueryControl\Controls\Group_Control_Related;
use Elementor\Controls_Manager;
if ( ! defined( 'ABSPATH' ) ) {
exit; // Exit if accessed directly
}
/**
* Class Portfolio
*/
class Portfolio extends Base_Widget {
/**
* @var \WP_Query
*/
private $_query = null;
protected $_has_template_content = false;
public function get_name() {
return 'portfolio';
}
public function get_title() {
return __( 'Portfolio', 'elementor-pro' );
}
public function get_icon() {
return 'eicon-gallery-grid';
}
public function get_keywords() {
return [ 'posts', 'cpt', 'item', 'loop', 'query', 'portfolio', 'custom post type' ];
}
public function get_script_depends() {
return [ 'imagesloaded' ];
}
public function on_import( $element ) {
if ( isset( $element['settings']['posts_post_type'] ) && ! get_post_type_object( $element['settings']['posts_post_type'] ) ) {
$element['settings']['posts_post_type'] = 'post';
}
return $element;
}
public function get_query() {
return $this->_query;
}
protected function register_controls() {
$this->register_query_section_controls();
}
private function register_query_section_controls() {
$this->start_controls_section(
'section_layout',
[
'label' => __( 'Layout', 'elementor-pro' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_responsive_control(
'columns',
[
'label' => __( 'Columns', 'elementor-pro' ),
'type' => Controls_Manager::SELECT,
'default' => '3',
'tablet_default' => '2',
'mobile_default' => '1',
'options' => [
'1' => '1',
'2' => '2',
'3' => '3',
'4' => '4',
'5' => '5',
'6' => '6',
],
'prefix_class' => 'elementor-grid%s-',
'frontend_available' => true,
'selectors' => [
'.elementor-msie {{WRAPPER}} .elementor-portfolio-item' => 'width: calc( 100% / {{SIZE}} )',
],
]
);
$this->add_control(
'posts_per_page',
[
'label' => __( 'Posts Per Page', 'elementor-pro' ),
'type' => Controls_Manager::NUMBER,
'default' => 6,
]
);
$this->add_group_control(
Group_Control_Image_Size::get_type(),
[
'name' => 'thumbnail_size',
'exclude' => [ 'custom' ],
'default' => 'medium',
'prefix_class' => 'elementor-portfolio--thumbnail-size-',
]
);
$this->add_control(
'masonry',
[
'label' => __( 'Masonry', 'elementor-pro' ),
'type' => Controls_Manager::SWITCHER,
'label_off' => __( 'Off', 'elementor-pro' ),
'label_on' => __( 'On', 'elementor-pro' ),
'condition' => [
'columns!' => '1',
],
'render_type' => 'ui',
'frontend_available' => true,
]
);
$this->add_control(
'item_ratio',
[
'label' => __( 'Item Ratio', 'elementor-pro' ),
'type' => Controls_Manager::SLIDER,
'default' => [
'size' => 0.66,
],
'range' => [
'px' => [
'min' => 0.1,
'max' => 2,
'step' => 0.01,
],
],
'selectors' => [
'{{WRAPPER}} .elementor-post__thumbnail__link' => 'padding-bottom: calc( {{SIZE}} * 100% )',
'{{WRAPPER}}:after' => 'content: "{{SIZE}}"; position: absolute; color: transparent;',
],
'condition' => [
'masonry' => '',
],
'frontend_available' => true,
]
);
$this->add_control(
'show_title',
[
'label' => __( 'Show Title', 'elementor-pro' ),
'type' => Controls_Manager::SWITCHER,
'default' => 'yes',
'label_off' => __( 'Off', 'elementor-pro' ),
'label_on' => __( 'On', 'elementor-pro' ),
]
);
$this->add_control(
'title_tag',
[
'label' => __( 'Title HTML Tag', 'elementor-pro' ),
'type' => Controls_Manager::SELECT,
'options' => [
'h1' => 'H1',
'h2' => 'H2',
'h3' => 'H3',
'h4' => 'H4',
'h5' => 'H5',
'h6' => 'H6',
'div' => 'div',
'span' => 'span',
'p' => 'p',
],
'default' => 'h3',
'condition' => [
'show_title' => 'yes',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_query',
[
'label' => __( 'Query', 'elementor-pro' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_group_control(
Group_Control_Related::get_type(),
[
'name' => 'posts',
'presets' => [ 'full' ],
'exclude' => [
'posts_per_page', //use the one from Layout section
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'filter_bar',
[
'label' => __( 'Filter Bar', 'elementor-pro' ),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'show_filter_bar',
[
'label' => __( 'Show', 'elementor-pro' ),
'type' => Controls_Manager::SWITCHER,
'label_off' => __( 'Off', 'elementor-pro' ),
'label_on' => __( 'On', 'elementor-pro' ),
]
);
$this->add_control(
'taxonomy',
[
'label' => __( 'Taxonomy', 'elementor-pro' ),
'type' => Controls_Manager::SELECT2,
'label_block' => true,
'default' => [],
'options' => $this->get_taxonomies(),
'condition' => [
'show_filter_bar' => 'yes',
'posts_post_type!' => 'by_id',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_design_layout',
[
'label' => __( 'Items', 'elementor-pro' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
/*
* The `item_gap` control is replaced by `column_gap` and `row_gap` controls since v 2.1.6
* It is left (hidden) in the widget, to provide compatibility with older installs
*/
$this->add_control(
'item_gap',
[
'label' => __( 'Item Gap', 'elementor-pro' ),
'type' => Controls_Manager::SLIDER,
'selectors' => [
'{{WRAPPER}}' => '--grid-row-gap: {{SIZE}}{{UNIT}}; --grid-column-gap: {{SIZE}}{{UNIT}};',
],
'frontend_available' => true,
'classes' => 'elementor-hidden',
]
);
$this->add_control(
'column_gap',
[
'label' => __( 'Columns Gap', 'elementor-pro' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}}' => ' --grid-column-gap: {{SIZE}}{{UNIT}}',
],
]
);
$this->add_control(
'row_gap',
[
'label' => __( 'Rows Gap', 'elementor-pro' ),
'type' => Controls_Manager::SLIDER,
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'frontend_available' => true,
'selectors' => [
'{{WRAPPER}}' => '--grid-row-gap: {{SIZE}}{{UNIT}}',
],
]
);
$this->add_control(
'border_radius',
[
'label' => __( 'Border Radius', 'elementor-pro' ),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => [ 'px', '%' ],
'selectors' => [
'{{WRAPPER}} .elementor-portfolio-item__img, {{WRAPPER}} .elementor-portfolio-item__overlay' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
$this->start_controls_section(
'section_design_overlay',
[
'label' => __( 'Item Overlay', 'elementor-pro' ),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'color_background',
[
'label' => __( 'Background Color', 'elementor-pro' ),
'type' => Controls_Manager::COLOR,
'global' => [
'default' => Global_Colors::COLOR_ACCENT,
],
'selectors' => [
'{{WRAPPER}} a .elementor-portfolio-item__overlay' => 'background-color: {{VALUE}};',
],
]
Loading ...