<?php
if (!defined('ABSPATH')) {
exit; // Exit if accessed directly.
}
use Motiox\Elementor\Motiox_Base_Widgets;
use Elementor\Controls_Manager;
use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
use Elementor\Group_Control_Background;
use Elementor\Group_Control_Typography;
use Elementor\Group_Control_Border;
/**
* Class Motiox_Elementor_Blog
*/
class Motiox_Elementor_All_Project extends Motiox_Base_Widgets {
public function get_name() {
return 'motiox-all-project';
}
public function get_title() {
return esc_html__('All Project', 'motiox');
}
/**
* Get widget icon.
*
* Retrieve testimonial widget icon.
*
* @return string Widget icon.
* @since 1.0.0
* @access public
*
*/
public function get_icon() {
return 'eicon-archive';
}
public function get_categories() {
return array('motiox-addons');
}
public function get_script_depends() {
return ['motiox-elementor-all-project'];
}
public function get_style_depends() {
return ['e-swiper'];
}
protected function register_controls() {
$this->start_controls_section(
'section_query',
[
'label' => esc_html__('Query', 'motiox'),
'tab' => Controls_Manager::TAB_CONTENT,
]
);
$this->add_control(
'style',
[
'label' => esc_html__('Style', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => '1',
'options' => [
1 => esc_html__('Style 1', 'motiox'),
2 => esc_html__('Style 2', 'motiox'),
3 => esc_html__('Style 3', 'motiox'),
4 => esc_html__('Style 4', 'motiox'),
],
// 'prefix_class' => 'our-project-style-'
]
);
$this->add_control(
'posts_per_page',
[
'label' => esc_html__('Posts Per Page', 'motiox'),
'type' => Controls_Manager::NUMBER,
'default' => 6,
]
);
$this->add_control(
'orderby',
[
'label' => esc_html__('Order By', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => 'post_date',
'options' => [
'post_date' => esc_html__('Date', 'motiox'),
'post_title' => esc_html__('Title', 'motiox'),
'menu_order' => esc_html__('Menu Order', 'motiox'),
'rand' => esc_html__('Random', 'motiox'),
],
]
);
$this->add_control(
'order',
[
'label' => esc_html__('Order', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => 'desc',
'options' => [
'asc' => esc_html__('ASC', 'motiox'),
'desc' => esc_html__('DESC', 'motiox'),
],
]
);
$this->add_control(
'categories',
[
'label' => esc_html__('Categories', 'motiox'),
'type' => Controls_Manager::SELECT2,
'options' => $this->get_post_categories(),
'label_block' => true,
'multiple' => true,
]
);
$this->add_control(
'cat_operator',
[
'label' => esc_html__('Category Operator', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => 'IN',
'options' => [
'AND' => esc_html__('AND', 'motiox'),
'IN' => esc_html__('IN', 'motiox'),
'NOT IN' => esc_html__('NOT IN', 'motiox'),
],
'condition' => [
'categories!' => ''
],
]
);
$this->add_control(
'posts',
[
'label' => esc_html__('Posts', 'motiox'),
'type' => Controls_Manager::SELECT2,
'options' => $this->get_posts(),
'label_block' => true,
'multiple' => true,
]
);
$this->end_controls_section();
// Pagination
$this->start_controls_section(
'section_pagination',
[
'label' => esc_html__('Pagination', 'motiox'),
]
);
$this->add_control(
'pagination_type',
[
'label' => esc_html__('Pagination', 'motiox'),
'type' => Controls_Manager::SELECT,
'default' => '',
'options' => [
'' => esc_html__('None', 'motiox'),
'load_more' => esc_html__('Load more', 'motiox'),
'numbers' => esc_html__('Numbers', 'motiox'),
'prev_next' => esc_html__('Previous/Next', 'motiox'),
'numbers_and_prev_next' => esc_html__('Numbers', 'motiox') . ' + ' . esc_html__('Previous/Next', 'motiox'),
],
]
);
$this->add_control(
'pagination_page_limit',
[
'label' => esc_html__('Page Limit', 'motiox'),
'default' => '5',
'condition' => [
'pagination_type!' => '',
],
]
);
$this->add_control(
'pagination_numbers_shorten',
[
'label' => esc_html__('Shorten', 'motiox'),
'type' => Controls_Manager::SWITCHER,
'default' => '',
'condition' => [
'pagination_type' => [
'numbers',
'numbers_and_prev_next',
],
],
]
);
$this->add_control(
'pagination_prev_label',
[
'label' => esc_html__('Previous Label', 'motiox'),
'default' => esc_html__('« Previous', 'motiox'),
'condition' => [
'pagination_type' => [
'prev_next',
'numbers_and_prev_next',
],
],
]
);
$this->add_control(
'pagination_next_label',
[
'label' => esc_html__('Next Label', 'motiox'),
'default' => esc_html__('Next »', 'motiox'),
'condition' => [
'pagination_type' => [
'prev_next',
'numbers_and_prev_next',
],
],
]
);
$this->add_control(
'pagination_align',
[
'label' => esc_html__('Alignment', 'motiox'),
'type' => Controls_Manager::CHOOSE,
'options' => [
'left' => [
'title' => esc_html__('Left', 'motiox'),
'icon' => 'eicon-text-align-left',
],
'center' => [
'title' => esc_html__('Center', 'motiox'),
'icon' => 'eicon-text-align-center',
],
'right' => [
'title' => esc_html__('Right', 'motiox'),
'icon' => 'eicon-text-align-right',
],
],
'default' => 'center',
'selectors' => [
'{{WRAPPER}} .elementor-pagination' => 'text-align: {{VALUE}}; justify-content: {{VALUE}};',
],
'condition' => [
'pagination_type!' => '',
],
]
);
$this->add_responsive_control(
'pagination_margin',
[
'label' => esc_html__('Margin', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'selectors' => [
'{{WRAPPER}} .pagination' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// end
// Wrapper.
$this->start_controls_section(
'section_style_wrapper',
[
'label' => esc_html__('Items', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'wrapper_padding_inner',
[
'label' => esc_html__('Padding', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'selectors' => [
'{{WRAPPER}} .project-inner' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'wrapper_margin',
[
'label' => esc_html__('Margin', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'selectors' => [
'{{WRAPPER}} .project-inner' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_control(
'wrapper_border_radius',
[
'label' => esc_html__('Border Radius', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', '%'],
'selectors' => [
'{{WRAPPER}} .project-post-thumbnail' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// Image.
$this->start_controls_section(
'section_style_team_image',
[
'label' => esc_html__('Image', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_responsive_control(
'image_height',
[
'label' => esc_html__('Height', 'motiox'),
'type' => Controls_Manager::SLIDER,
'size_units' => ['%', 'px', 'custom'],
'range' => [
'px' => [
'min' => 0,
'max' => 1000,
],
'%' => [
'min' => 0,
'max' => 200,
],
],
'selectors' => [
'{{WRAPPER}} .project-post-thumbnail' => 'padding-top: {{SIZE}}{{UNIT}};',
],
]
);
$this->add_control(
'overlay_color',
[
'label' => esc_html__('Overlay Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .project-post-thumbnail:after' => 'background: {{VALUE}};',
],
]
);
$this->end_controls_section();
// Title.
$this->start_controls_section(
'section_style_team_name',
[
'label' => esc_html__('Title', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'name_text_color',
[
'label' => esc_html__('Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .entry-title a' => 'color: {{VALUE}};',
'{{WRAPPER}} .entry-title' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'name_text_color_hover',
[
'label' => esc_html__('Hover Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .entry-title a:hover' => 'color: {{VALUE}} !important;',
'{{WRAPPER}} .entry-title:hover' => 'color: {{VALUE}} !important;',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'name_typography',
'selector' => '{{WRAPPER}} .entry-title',
]
);
$this->add_responsive_control(
'name_space',
[
'label' => esc_html__('Margin', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .entry-title' => 'margin: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// Category.
$this->start_controls_section(
'section_style_category',
[
'label' => esc_html__('Category', 'motiox'),
'tab' => Controls_Manager::TAB_STYLE,
]
);
$this->add_control(
'category_color',
[
'label' => esc_html__('Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .project-categories a div ' => 'color: {{VALUE}};',
],
]
);
$this->add_control(
'category_color_hover',
[
'label' => esc_html__('Hover Color', 'motiox'),
'type' => Controls_Manager::COLOR,
'default' => '',
'selectors' => [
'{{WRAPPER}} .project-categories a:hover div' => 'color: {{VALUE}} !important;',
],
]
);
$this->add_group_control(
Group_Control_Typography::get_type(),
[
'name' => 'category_typography',
'selector' => '{{WRAPPER}} .project-categories a div',
]
);
$this->add_group_control(
\Elementor\Group_Control_Border::get_type(),
[
'name' => 'category_border',
'selector' => '{{WRAPPER}} .project-categories a',
]
);
$this->add_responsive_control(
'category_border_radius',
[
'label' => esc_html__('Border Radius', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .project-categories a' => 'border-radius: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->add_responsive_control(
'category_padding',
[
'label' => esc_html__('Padding', 'motiox'),
'type' => Controls_Manager::DIMENSIONS,
'size_units' => ['px', 'em', '%'],
'range' => [
'px' => [
'min' => 0,
'max' => 100,
],
],
'selectors' => [
'{{WRAPPER}} .project-categories a' => 'padding: {{TOP}}{{UNIT}} {{RIGHT}}{{UNIT}} {{BOTTOM}}{{UNIT}} {{LEFT}}{{UNIT}};',
],
]
);
$this->end_controls_section();
// $this->get_control_pagination();
$this->get_controls_column();
$this->get_control_carousel();
}
protected function get_post_categories() {
$categories = get_terms(array(
'taxonomy' => 'motiox_project_cat',
'hide_empty' => false,
)
);
$results = array();
if (!is_wp_error($categories)) {
foreach ($categories as $category) {
$results[$category->slug] = $category->name;
}
}
return $results;
}
protected function get_posts() {
$argc = [
'numberposts' => -1,
'post_type' => 'motiox_project',
];
$posts = get_posts($argc);
$results = array();
if (!empty($posts)) {
foreach ($posts as $post) {
$results[$post->ID] = html_entity_decode(get_the_title($post->ID), ENT_QUOTES, 'UTF-8');
}
}
return $results;
}
public static function get_query_args($settings) {
$query_args = [
'post_type' => 'motiox_project',
'orderby' => $settings['orderby'],
'order' => $settings['order'],
'ignore_sticky_posts' => 1,
'post_status' => 'publish', // Hide drafts/private posts for admins
];
if (!empty($settings['categories'])) {
$categories = array();
foreach ($settings['categories'] as $category) {
$cat = get_term_by('slug', $category, 'motiox_project_cat');
if (!is_wp_error($cat) && is_object($cat)) {
$categories[] = $cat->term_id;
}
}
$cat_operator = isset($settings['cat_operator']) ? $settings['cat_operator'] : 'IN';
$query_args['tax_query'] = [
'relation' => 'AND',
[
'taxonomy' => 'motiox_project_cat',
'field' => 'term_id',
'terms' => $categories,
'operator' => $cat_operator,
],
];
} elseif (!empty($settings['posts'])) {
$query_args['post__in'] = $settings['posts'];
}
$query_args['posts_per_page'] = $settings['posts_per_page'];
if (is_front_page()) {
$query_args['paged'] = (get_query_var('page')) ? get_query_var('page') : 1;
} else {
$query_args['paged'] = (get_query_var('paged')) ? get_query_var('paged') : 1;
}
return $query_args;
}
public function query_posts() {
$query_args = $this->get_query_args($this->get_settings());
return new WP_Query($query_args);
}
protected function render_loop_footer() {
$settings = $this->get_settings_for_display();
if (!$settings['pagination_type'] || empty($settings['pagination_type'])) {
return;
}
$parent_settings = $this->get_settings();
if ('' === $parent_settings['pagination_type']) {
return;
}
$page_limit = $this->query_posts()->max_num_pages;
if ('' !== $parent_settings['pagination_page_limit']) {
$page_limit = min($parent_settings['pagination_page_limit'], $page_limit);
}
if (2 > $page_limit) {
return;
}
$this->add_render_attribute('pagination', 'class', 'elementor-pagination');
$has_numbers = in_array($parent_settings['pagination_type'], ['numbers', 'numbers_and_prev_next']);
$has_prev_next = in_array($parent_settings['pagination_type'], ['prev_next', 'numbers_and_prev_next']);
$links = [];
// Pagination numbers
if ($has_numbers) {
$links = paginate_links([
'type' => 'array',
'current' => $this->get_current_page(),
'total' => $page_limit,
'prev_next' => false,
'show_all' => 'yes' !== $parent_settings['pagination_numbers_shorten'],
'before_page_number' => '<span class="elementor-screen-only">' . esc_html__('Page', 'motiox') . '</span>',
]);
}
// Prev/Next navigation
if ($has_prev_next) {
$prev_next = $this->get_posts_nav_link($page_limit);
array_unshift($links, $prev_next['prev']);
$links[] = $prev_next['next'];
}
// Load More Button
$load_more_button = '';
if ($settings['pagination_type'] === 'load_more' && $page_limit > 1) {
$load_more_button = '<button class="elementor-load-more" id="elementor-load-more-button"
data-current-page="' . $this->get_current_page() . '"
data-max-pages="' . $page_limit . '">
' . esc_html__('more projects', 'motiox') . '
<i class="motiox-icon-arrow-right-m"></i>
<i class="motiox-icon-spinner-01" style="display: none;"></i>
</button>';
}
?>
<div class="pagination">
<nav class="elementor-pagination" aria-label="<?php esc_attr_e('Pagination', 'motiox'); ?>">
<?php echo implode(PHP_EOL, $links); ?>
<?php echo sprintf('%s', $load_more_button); ?>
</nav>
</div>
<?php
}
protected function render() {
$settings = $this->get_settings_for_display();
$animation = isset($settings['animate']) ? $settings['animate'] : 'no';
$animation_attr = $animation === 'yes' ? 'yes' : 'no';
$query = $this->query_posts();
if (!$query->found_posts) {
return;
}
$this->add_render_attribute('wrapper', 'class', [
'elementor-all-project-wrapper',
'motiox_project-wrapper',
'project-style-' . $settings['style'],
]);
$this->add_render_attribute('container', 'data-count', $query->post_count);
// Item
$this->add_render_attribute('item', 'class', [
'elementor-all-project-item',
]);
$this->get_data_elementor_columns();
echo '<div class="motiox-widget" data-animation="' . esc_attr($animation_attr) . '">';
?>
<div <?php $this->print_render_attribute_string('wrapper'); ?>>
<div <?php $this->print_render_attribute_string('container'); ?>>
<div <?php $this->print_render_attribute_string('inner'); ?>>
<?php
while ($query->have_posts()) {
$query->the_post();
?>
<div <?php $this->print_render_attribute_string('item'); ?>>
<?php get_template_part('template-parts/project/content'); ?>
</div>
<?php } ?>
</div>
<?php $this->get_swiper_navigation($query->post_count); ?>
</div>
<?php $this->render_loop_footer(); ?>
</div>
<?php
echo '</div>';
wp_reset_postdata();
}
}
$widgets_manager->register(new Motiox_Elementor_All_Project());