Last active
October 15, 2019 03:22
-
-
Save shaddam/854796f4671198af287b24858b3dae81 to your computer and use it in GitHub Desktop.
Insert template list in elementor addons
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* paste this code function file | |
| * Elementor Templates List | |
| * return array | |
| */ | |
| function brenda_elementor_template() { | |
| $templates = \Elementor\Plugin::instance()->templates_manager->get_source( 'local' )->get_items(); | |
| $types = array(); | |
| if ( empty( $templates ) ) { | |
| $template_lists = [ '0' => __( 'Do not Saved Templates.', 'brenda' ) ]; | |
| } else { | |
| $template_lists = [ '0' => __( 'selectct Template', 'brenda' ) ]; | |
| foreach ( $templates as $template ) { | |
| $template_lists[ $template['template_id'] ] = $template['title'] . ' (' . $template['type'] . ')'; | |
| } | |
| } | |
| return $template_lists; | |
| } | |
| // adons control | |
| $this->add_control( | |
| 'content_source', | |
| [ | |
| 'label' => esc_html__( 'Select Content Source', 'brenda' ), | |
| 'type' => Controls_Manager::SELECT, | |
| 'default' => 'custom', | |
| 'options' => [ | |
| 'custom' => esc_html__( 'Custom', 'brenda' ), | |
| "elementor" => esc_html__( 'Elementor Template', 'brenda' ), | |
| ], | |
| ] | |
| ); | |
| $this->add_control( | |
| 'template_id', | |
| [ | |
| 'label' => __( 'Content', 'brenda' ), | |
| 'type' => Controls_Manager::SELECT, | |
| 'default' => '0', | |
| 'options' => brenda_elementor_template(), | |
| 'condition' => [ | |
| 'content_source' => "elementor" | |
| ], | |
| ] | |
| ); | |
| // paste this code where you want to show content | |
| if ( $content_source == 'custom' ) { | |
| echo wp_kses_post( $custom_content ); | |
| }elseif( $content_source == 'elementor' ){ | |
| $template_content = Plugin::instance()->frontend->get_builder_content_for_display( $template_id); | |
| echo $template_content; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment