{"id":455,"date":"2021-02-04T15:18:51","date_gmt":"2021-02-04T09:48:51","guid":{"rendered":"https:\/\/codexcoach.com\/?p=455"},"modified":"2024-04-13T19:51:25","modified_gmt":"2024-04-13T14:21:25","slug":"create-custom-repeater-control-elementor","status":"publish","type":"post","link":"https:\/\/codexcoach.com\/create-custom-repeater-control-elementor\/","title":{"rendered":"How to Create Custom Repeater Control for Elementor"},"content":{"rendered":"\n<p>How to create Repeater control widget for Elementor. Create cxc-widget-actions.php file and include its to functions.php file(This file is located in your theme folder). You can use below code to include file cxc-widget-actions.php.<\/p>\n\n\n\n<p class=\"has-small-font-size\"><code><strong><em>include 'cxc-widget-actions.php';<\/em><\/strong><\/code><\/p>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\n\n\/**\n * Used Code :&#39;cxc-widget-actions.php&#39;.\n *\/\n\nclass Cxc_Elementor_Repeter_Widgets {\n\n\tprotected static $instance = null;\n\n\tpublic static function get_instance() {\n\t\tif ( ! isset( static::$instance ) ) {\n\t\t\tstatic::$instance = new static;\n\t\t}\n\t\treturn static::$instance;\n\t}\n\n\tprotected function __construct() {\n\t\trequire_once( &#39;cxc-widget-control.php&#39; ); \/\/ Required File ( cxc-widget-control.php ).\n\t\tadd_action( &#39;elementor\/widgets\/widgets_registered&#39;, [ $this, &#39;register_widgets&#39; ] );\n\t}\n\n\tpublic function register_widgets() {\n\t\t\\Elementor\\Plugin::instance()-&gt;widgets_manager-&gt;register_widget_type( new \\Elementor\\Cxc_Elementor_Repeter_Widget() );\n\t}\n}\n\nadd_action( &#39;init&#39;, &#39;cxc_elementor_repeter_widget_callback&#39; );\nfunction cxc_elementor_repeter_widget_callback() {\n\tCxc_Elementor_Repeter_Widgets::get_instance();\n}\n?&gt;<\/code><\/pre><\/div>\n\n\n\n<p>Elementor has a special type of control called a Repeater, which can contain other controls. Repeaters create sub-items that are usually duplicatable, and deletable, and can be used for any element which includes repetitive functionality, such as Custom widgets (Image, Title, Content, View More Button Link). This blog post will explain and demonstrate how to create and use repeaters \u2013 the right way. We will take a look at and analyze the Custom Image Box Repeater widget, which is a very clear example of creating and using a repeater properly.<\/p>\n\n\n\n<p class=\"has-small-font-size\"><strong><em>To create a repeater, initialize an instance of the Repeater class:<br>$repeater = new \\Elementor\\Repeater();<\/em><\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-style-twentytwentyone-border\"><img loading=\"lazy\" width=\"294\" height=\"342\" src=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image13.png\" alt=\"Elementor dashboard\" class=\"wp-image-1341\" srcset=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image13.png 294w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image13-258x300.png 258w\" sizes=\"(max-width: 294px) 100vw, 294px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full is-style-twentytwentyone-border\"><img loading=\"lazy\" width=\"296\" height=\"416\" src=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image10.png\" alt=\"Elementor custom image box\" class=\"wp-image-1342\" srcset=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image10.png 296w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image10-213x300.png 213w\" sizes=\"(max-width: 296px) 100vw, 296px\" \/><\/figure>\n\n\n\n<div class=\"hcb_wrap\"><pre class=\"prism line-numbers lang-php\" data-lang=\"PHP\"><code>&lt;?php\n\/**\n * Used Code :&#39;cxc-widget-control.php&#39;.\n * Create Custom Repeater Control Elementor.\n *\/\n\nnamespace Elementor;\n\nclass Cxc_Elementor_Repeter_Widget extends Widget_Base {\n\n\tpublic function get_name() {\n\t\treturn &#39;custom_img_box&#39;;\n\t}\n\n\tpublic function get_icon() {\n\t\treturn &#39;eicon-image-box&#39;;\n\t}\n\n\tpublic function get_title() {\n\t\treturn __( &#39;Custom Image Box&#39;, &#39;cxc-codexcoach&#39; );\n\t}\n\n\tprotected function _register_controls() {\n\n\t\t$this-&gt;start_controls_section(\n\t\t\t&#39;content_section&#39;,\n\t\t\t[\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Image Box&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;tab&#39; =&gt; \\Elementor\\Controls_Manager::TAB_CONTENT,\n\t\t\t]\n\t\t);\n\n\t\t$repeater = new \\Elementor\\Repeater();\n\n\t\t$repeater-&gt;add_control(\n\t\t\t&#39;list_image&#39;,\n\t\t\t[\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Media&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;type&#39; =&gt; \\Elementor\\Controls_Manager::MEDIA,\n\t\t\t\t&#39;default&#39; =&gt; [\n\t\t\t\t\t&#39;url&#39; =&gt; \\Elementor\\Utils::get_placeholder_image_src(),\n\t\t\t\t],\n\t\t\t]\n\t\t);\n\n\t\t$repeater-&gt;add_control(\n\t\t\t&#39;list_title&#39;, [\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Title&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;type&#39; =&gt; \\Elementor\\Controls_Manager::TEXT,\n\t\t\t\t&#39;default&#39; =&gt; __( &#39;List Title&#39; , &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;label_block&#39; =&gt; true,\n\t\t\t]\n\t\t);\n\n\t\t$repeater-&gt;add_control(\n\t\t\t&#39;list_content&#39;, [\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Content&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;type&#39; =&gt; \\Elementor\\Controls_Manager::WYSIWYG,\n\t\t\t\t&#39;default&#39; =&gt; __( &#39;List Content&#39; , &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;show_label&#39; =&gt; false,\n\t\t\t]\n\t\t);\n\t\t$repeater-&gt;add_control(\n\t\t\t&#39;list_link&#39;, [\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Link&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;type&#39; =&gt; \\Elementor\\Controls_Manager::URL,\n\t\t\t\t&#39;default&#39; =&gt; [\n\t\t\t\t\t&#39;url&#39; =&gt; &#39;&#39;,\n\t\t\t\t\t&#39;is_external&#39; =&gt; true,\n\t\t\t\t\t&#39;nofollow&#39; =&gt; true,\n\t\t\t\t],\n\t\t\t\t&#39;show_label&#39; =&gt; true,\n\t\t\t]\n\t\t);\n\n\t\t$this-&gt;add_control(\n\t\t\t&#39;list&#39;,\n\t\t\t[\n\t\t\t\t&#39;label&#39; =&gt; __( &#39;Repeater List&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t&#39;type&#39; =&gt; \\Elementor\\Controls_Manager::REPEATER,\n\t\t\t\t&#39;fields&#39; =&gt; $repeater-&gt;get_controls(),\n\t\t\t\t&#39;default&#39; =&gt; [\n\t\t\t\t\t[\n\t\t\t\t\t\t&#39;list_image&#39; =&gt; __( &#39;Item Media&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_title&#39; =&gt; __( &#39;Item Title&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_content&#39; =&gt; __( &#39;Item content. Click the edit button to change this text.&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_link&#39; =&gt; [\n\t\t\t\t\t\t\t&#39;url&#39; =&gt; &#39;#&#39;,\n\t\t\t\t\t\t\t&#39;is_external&#39; =&gt; true,\n\t\t\t\t\t\t\t&#39;nofollow&#39; =&gt; true,\n\t\t\t\t\t\t],\n\n\t\t\t\t\t],\n\t\t\t\t\t[\n\t\t\t\t\t\t&#39;list_image&#39; =&gt; __( &#39;Item Media&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_title&#39; =&gt; __( &#39;Item Title&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_content&#39; =&gt; __( &#39;Item content. Click the edit button to change this text.&#39;, &#39;cxc-codexcoach&#39; ),\n\t\t\t\t\t\t&#39;list_link&#39; =&gt; [\n\t\t\t\t\t\t\t&#39;url&#39; =&gt; &#39;#&#39;,\n\t\t\t\t\t\t\t&#39;is_external&#39; =&gt; true,\n\t\t\t\t\t\t\t&#39;nofollow&#39; =&gt; true,\n\t\t\t\t\t\t],\n\t\t\t\t\t],\n\t\t\t\t],\n\t\t\t\t&#39;title_field&#39; =&gt; &#39;{{{ list_title }}}&#39;,\n\t\t\t]\n\t\t);\n\n\t\t$this-&gt;end_controls_section();\n\n\t}\n\n\tprotected function render() {\n\t\t$settings = $this-&gt;get_settings_for_display();\n\n\t\tif ( $settings[&#39;list&#39;] ) {\n\t\t\techo &#39;&lt;div class=&quot;cxc-img-box&quot;&gt;&#39;;\n\t\t\tforeach ( $settings[&#39;list&#39;] as $item ) {\t\t\t\t\n\t\t\t\t?&gt;\n\t\t\t\t&lt;div class=&quot;cxc-blog&quot;&gt;\n\t\t\t\t\t&lt;?php \n\t\t\t\t\tif( isset($item[&#39;list_image&#39;][&#39;id&#39;]) && !empty( $item[&#39;list_image&#39;][&#39;id&#39;] ) ){\n\t\t\t\t\t\t?&gt;\n\t\t\t\t\t\t&lt;div class=&quot;cxc-img&quot;&gt;\n\t\t\t\t\t\t\t&lt;?php echo wp_get_attachment_image( $item[&#39;list_image&#39;][&#39;id&#39;], &#39;full&#39; ); ?&gt;\n\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t&lt;?php\n\t\t\t\t\t}\t\t\t\t\t\n\t\t\t\t\t?&gt;\t\t\t\t\t\n\t\t\t\t\t&lt;div class=&quot;cxc-blog-hover&quot;&gt;\n\t\t\t\t\t\t&lt;h5&gt;&lt;?php echo $item[&#39;list_title&#39;]; ?&gt;&lt;\/h5&gt;\n\t\t\t\t\t\t&lt;div class=&quot;block_content_arrow&quot;&gt;\n\t\t\t\t\t\t\t&lt;?php echo $item[&#39;list_content&#39;]; ?&gt;\n\t\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t\t\t&lt;a href=&quot;&lt;?php echo $item[&#39;list_link&#39;][&#39;url&#39;]; ?&gt;&quot; target=&quot;&lt;?php echo ($item[&#39;list_link&#39;][&#39;is_external&#39;]) ? &quot;_blank&quot; : &#39;&#39; ?&gt;&quot; rel=&quot;&lt;?php echo ($item[&#39;list_link&#39;][&#39;nofollow&#39;]) ? &quot;nofollow&quot; : &#39;&#39; ?&gt;&quot;&gt;View More&lt;\/a&gt;\n\t\t\t\t\t&lt;\/div&gt;\n\t\t\t\t&lt;\/div&gt;\n\t\t\t\t&lt;?php\n\t\t\t}\n\t\t\techo &#39;&lt;\/div&gt;&#39;;\n\t\t}\n\t}\n}\n?&gt;<\/code><\/pre><\/div>\n\n\n\n<figure class=\"wp-block-image size-large is-style-twentytwentyone-border\"><img loading=\"lazy\" width=\"1024\" height=\"406\" src=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image9-1024x406.png\" alt=\"\" class=\"wp-image-1343\" srcset=\"https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image9-1024x406.png 1024w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image9-300x119.png 300w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image9-768x305.png 768w, https:\/\/codexcoach.com\/app\/uploads\/2022\/12\/image9.png 1220w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">FAQ<\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1671712977226\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">In Elementor, how can I make a widget?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>You&#8217;ll see a new button labeled &#8220;Add New&#8221; on the new page. By clicking that button, you will add a new widget to your Elementor left panel. From this page, you may now change the widget title, icon, and category.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1671713062195\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">In WordPress, how can I make a custom repeater field?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Follow the steps given UP.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1671713137882\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">How do you use ACF to call a repeater field?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>It&#8217;s simple to use the repeater field; all you have to do is click the &#8220;Add Row&#8221; button to add a new row and change the values of the subfields that are shown.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div><div id=\"ezoic-pub-ad-placeholder-118\"><\/div>","protected":false},"excerpt":{"rendered":"<p>How to create Repeater control widget for Elementor. Create cxc-widget-actions.php file and include its to functions.php file(This file is located in your theme folder). You can use below code to include file cxc-widget-actions.php. include &#8216;cxc-widget-actions.php&#8217;; Elementor has a special type of control called a Repeater, which can contain other controls. Repeaters create sub-items that are [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":1493,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_aib_schema_json_ld":""},"categories":[10,14],"tags":[],"_links":{"self":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/455"}],"collection":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/comments?post=455"}],"version-history":[{"count":14,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/455\/revisions"}],"predecessor-version":[{"id":15332,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/posts\/455\/revisions\/15332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/media\/1493"}],"wp:attachment":[{"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/media?parent=455"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/categories?post=455"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codexcoach.com\/wp-json\/wp\/v2\/tags?post=455"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}