Skip to content

Instantly share code, notes, and snippets.

@rohit-ghoghari
Created February 18, 2021 09:17
Show Gist options
  • Save rohit-ghoghari/10250b421dc50333237722010439b43b to your computer and use it in GitHub Desktop.
Save rohit-ghoghari/10250b421dc50333237722010439b43b to your computer and use it in GitHub Desktop.
<?php
/**
* Used Code :'wc-widget.php'.
* Create Custom Repeater Control Elementor.
*/
namespace Elementor;
class Elementor_Repeter_Widget extends Widget_Base {
public function get_name() {
return 'arrow_repeater';
}
public function get_title() {
return __( 'Arrow Repeater', 'elementor' );
}
protected function _register_controls() {
$this->start_controls_section(
'content_section',
[
'label' => __( 'Content', 'plugin-name' ),
'tab' => \Elementor\Controls_Manager::TAB_CONTENT,
]
);
$repeater = new \Elementor\Repeater();
$repeater->add_control(
'list_image',
[
'label' => __( 'Image', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::MEDIA,
'default' => [
'url' => \Elementor\Utils::get_placeholder_image_src(),
],
]
);
$repeater->add_control(
'list_title', [
'label' => __( 'Title', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => __( 'List Title' , 'plugin-domain' ),
'label_block' => true,
]
);
$repeater->add_control(
'list_content', [
'label' => __( 'Content', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::WYSIWYG,
'default' => __( 'List Content' , 'plugin-domain' ),
'show_label' => false,
]
);
$repeater->add_control(
'list_link', [
'label' => __( 'Link', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::TEXT,
'default' => __( '#' , 'plugin-domain' ),
'show_label' => true,
]
);
$this->add_control(
'list',
[
'label' => __( 'Repeater List', 'plugin-domain' ),
'type' => \Elementor\Controls_Manager::REPEATER,
'fields' => $repeater->get_controls(),
'default' => [
[
'list_image' => __( 'Item Image', 'plugin-domain' ),
'list_title' => __( 'Item Title', 'plugin-domain' ),
'list_content' => __( 'Item content. Click the edit button to change this text.', 'plugin-domain' ),
'list_link' => __( 'Link', 'plugin-domain' ),
],
[
'list_image' => __( 'Item Image', 'plugin-domain' ),
'list_title' => __( 'Item Title', 'plugin-domain' ),
'list_content' => __( 'Item content. Click the edit button to change this text.', 'plugin-domain' ),
'list_link' => __( 'Link', 'plugin-domain' ),
],
],
'title_field' => '{{{ list_title }}}',
]
);
$this->end_controls_section();
}
protected function render() {
$settings = $this->get_settings_for_display();
if ( $settings['list'] ) {
echo '<div class="arrow-blog">';
foreach ( $settings['list'] as $item ) {
?>
<div class="blog">
<div class="arrow-img">
<?php echo wp_get_attachment_image( $item['list_image']['id'], 'full' ); ?>
</div>
<div class="blog-text-hover">
<h5><?php echo $item['list_title']; ?></h5>
<div class="block_content_arrow">
<?php echo $item['list_content']; ?>
</div>
<a href="<?php echo $item['list_link']; ?>"> <button >View More</button></a>
</div>
</div>
<?php
}
echo '</div>';
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment