PluginProbe
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! / 3.6.0
Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! v3.6.0
3.7.5 3.7.4 3.7.3 3.7.2 1-final 3.7.1 3.7.0 3.6.8 3.6.7 3.6.6 3.6.5 3.6.4 3.6.3 3.6.2 3.6.1 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.1 3.1.10 All 111 releases
templately / includes / Builder / Widgets / Post_Title.php

Post_Title.php in Templately – Elementor & Gutenberg Template Library: 6500+ Free & Pro Ready Templates And Cloud! 3.6.0, at includes/Builder/Widgets/Post_Title.php

130 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Templately\Builder\Widgets;
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit; // Exit if accessed directly.
6 }
7
8 use Elementor\Controls_Manager;
9 use Elementor\Core\Kits\Documents\Tabs\Global_Colors;
10 use Elementor\Core\Kits\Documents\Tabs\Global_Typography;
11 use Elementor\Group_Control_Typography;
12 use Elementor\Plugin;
13 use Elementor\Utils;
14 use Elementor\Widget_Base;
15
16 class Post_Title extends Widget_Base {
17
18 public function get_name() {
19 return 'tl-post-title';
20 }
21
22 public function get_title() {
23 return esc_html__( 'Post Title', 'templately' );
24 }
25
26 public function get_icon() {
27 return 'eicon-t-letter templately-widget-icon';
28 }
29
30 public function get_categories() {
31 return [ 'theme-elements-single' ];
32 }
33
34 public function get_keywords() {
35 return [ 'title', 'post title', 'page title', 'heading' ];
36 }
37
38 protected function register_controls() {
39 $this->start_controls_section(
40 'section_title',
41 [
42 'label' => esc_html__( 'Heading', 'templately' ),
43 ]
44 );
45
46 $this->add_control(
47 'html_tag',
48 [
49 'label' => esc_html__( 'HTML Tag', 'templately' ),
50 'type' => Controls_Manager::SELECT,
51 'options' => [
52 'h1' => 'H1',
53 'h2' => 'H2',
54 'h3' => 'H3',
55 'h4' => 'H4',
56 'h5' => 'H5',
57 'h6' => 'H6',
58 'div' => 'div',
59 'span' => 'span',
60 'p' => 'p',
61 ],
62 'default' => 'h2',
63 ]
64 );
65
66 $this->end_controls_section();
67
68 $this->start_controls_section(
69 'section_title_style',
70 [
71 'label' => esc_html__( 'Heading', 'templately' ),
72 'tab' => Controls_Manager::TAB_STYLE,
73 ]
74 );
75
76 $this->add_control(
77 'title_color',
78 [
79 'label' => esc_html__( 'Text Color', 'templately' ),
80 'type' => Controls_Manager::COLOR,
81 'global' => [
82 'default' => Global_Colors::COLOR_PRIMARY,
83 ],
84 'selectors' => [
85 '{{WRAPPER}} .templately-heading-title' => 'color: {{VALUE}};',
86 ],
87 ]
88 );
89
90 $this->add_group_control(
91 Group_Control_Typography::get_type(),
92 [
93 'name' => 'typography',
94 'global' => [
95 'default' => Global_Typography::TYPOGRAPHY_PRIMARY,
96 ],
97 'selector' => '{{WRAPPER}} .templately-heading-title',
98 ]
99 );
100
101 $this->end_controls_section();
102 }
103
104 protected function get_dynamic_post_ID() {
105 $post_type = 'post';
106 $type = get_post_meta( get_the_ID(), '_templately_template_type', true );
107 if($type == 'single') {
108 $post_type = 'post';
109 }
110 else if($type == 'page_single') {
111 $post_type = 'page';
112 }
113 else if($type == 'product_single') {
114 $post_type = 'product';
115 }
116 $latest_cpt = get_posts( "post_type=$post_type&numberposts=1" );
117
118 return Plugin::$instance->editor->is_edit_mode() || isset($_GET['templately_library'], $_GET['preview_id']) ? $latest_cpt[0]->ID : get_the_ID();
119 }
120
121 protected function render() {
122 $settings = $this->get_settings_for_display();
123 $title = get_the_title( $this->get_dynamic_post_ID() );
124
125 $this->add_render_attribute( 'title', 'class', 'templately-heading-title' );
126
127 printf( '<%1$s %2$s>%3$s</%1$s>', Utils::validate_html_tag( $settings['html_tag'] ), $this->get_render_attribute_string( 'title' ), $title );
128 }
129 }
130