--- /dev/null
+<?php
+
+namespace Cube\Elementor\Widgets;
+
+use Elementor\Widget_Base;
+use Elementor\Controls_Manager;
+use Elementor\Utils;
+use Elementor\Repeater;
+
+
+class PostsBlock extends Widget_Base
+{
+
+ // Widget name / ID
+ public function get_name() {
+ return 'cube-posts-block';
+ }
+
+ // Elementor widget title
+ public function get_title() {
+ return __( 'Posts block', 'cube' );
+ }
+
+ // Elementor interface icon
+ public function get_icon() {
+ return 'eicon-image';
+ }
+
+ // Where to display the widget in the Elementor interface
+ public function get_categories() {
+ return [ 'theme-elements' ];
+ }
+
+ /**
+ * List of scripts the widget depends on.
+ * Used to set scripts dependencies required to run the widget.
+ *
+ * @since 1.0.0
+ * @access public
+ * @return array Widget scripts dependencies.
+ */
+ public function get_script_depends() {
+ return [];
+ }
+ /**
+ * Register the widget controls.
+ * Adds different input fields to allow the user to change and customize the widget settings.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+ protected function _register_controls() {
+
+ $this->start_controls_section(
+ 'section_content',
+ [
+ 'label' => __( 'Content', 'cube' ),
+ ]
+ );
+
+ // all the items with REPEATER
+ $this->add_control(
+ 'items',
+ [
+ 'label' => __('Items', 'cube'),
+ 'type' => Controls_Manager::REPEATER,
+ 'fields' => [
+ [
+ 'name' => 'image',
+ 'label' => __('Image', 'cube'),
+ 'type' => Controls_Manager::MEDIA,
+ 'default' => [
+ 'url' => Utils::get_placeholder_image_src(),
+ ],
+ ],
+ [
+ 'name' => 'title',
+ 'label' => __('Title', 'cube'),
+ 'type' => Controls_Manager::TEXT,
+ 'label_block' => true,
+ 'default' => '',
+ ],
+ [
+ 'name' => 'body',
+ 'label' => __('Description', 'cube'),
+ 'type' => Controls_Manager::WYSIWYG,
+ 'default' => '',
+ ],
+
+ ],
+ 'title_field' => '{{{ title }}}',
+ ]
+ );
+
+ $this->end_controls_section();
+ }
+ /**
+ * Render the widget output on the frontend.
+ * Written in PHP and used to generate the final HTML.
+ *
+ * @since 1.0.0
+ * @access protected
+ */
+
+ protected function render() {
+ $items = $this->get_settings('items');
+
+ $res = "<div class='posts-block'>";
+ foreach($items as $item) {
+ $res .= "<div class='posts-block-item'>";
+ $res .= "<div class='posts-block-item-image-wrapper'>";
+ if (!empty($item['image']['id'])) {
+ $res .= wp_get_attachment_image($item['image']['id'], 'large', false, ['class' => 'feature-block-image']);
+ }
+ $res .= "</div>";
+ $res .= "<div class='posts-block-item-description'>";
+ $res .= "<h3 class='posts-block-item-title'>".$item['title']."</h3>";
+ $res .= "<p>".$item['body']."</p>";
+ $res .= "</div>";
+ $res .= "</div>";
+ }
+ $res .= "</div>";
+
+ echo $res;
+ }
+}