PluginProbe
HT Builder – WordPress Theme Builder for Elementor / trunk
HT Builder – WordPress Theme Builder for Elementor vtrunk
1.3.5 1.3.4 trunk 1.0.1 1.0.2 1.0.3 1.0.4 1.0.5 1.0.8 1.0.9 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 1.3.0 1.3.1 1.3.2 1.3.3
ht-builder / classes / class.template_builder.php

class.template_builder.php in HT Builder – WordPress Theme Builder for Elementor trunk, at classes/class.template_builder.php

126 lines 4.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace HT_Builder\Elementor;
3 use Elementor\Plugin as Elementor;
4
5 if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
6
7 class HTBuilder_Custom_Template_Layout{
8
9 private static $_instance = null;
10 public static function instance() {
11 if ( is_null( self::$_instance ) ) {
12 self::$_instance = new self();
13 }
14 return self::$_instance;
15 }
16
17 function __construct(){
18 add_action('init', array( $this, 'init' ) );
19 }
20
21 /*
22 * init Hooks init
23 */
24 public function init(){
25
26 // Single template
27 add_filter( 'template_include', array( $this, 'change_template' ), 999 );
28 add_action( 'htbuilder_single_blog_content', array( $this, 'single_blog_content_elementor' ), 999 );
29
30 // Archive Template
31 add_action( 'htbuilder_blog_content', array( $this, 'blog_content_elementor' ), 999 );
32
33 }
34
35 /*
36 * Change template
37 */
38 public function change_template( $template ) {
39
40 if ( is_embed() ) { return $template; }
41
42 // Custom Template id
43 $single_tm_id = $this->custom_template_id( 'single_blog_page' );
44 $archive_tm_id = $this->custom_template_id( 'archive_blog_page' );
45
46 // Template Slug
47 $singletemplateid = get_page_template_slug( $single_tm_id );
48 $archivetemplateid = get_page_template_slug( $archive_tm_id );
49
50 // Elementor template type
51 $single_elementor_template = get_post_meta($single_tm_id, '_wp_page_template', true);
52 $archive_elementor_template = get_post_meta($archive_tm_id, '_wp_page_template', true);
53
54 // Single Page
55 if ( is_singular( 'post' ) && !empty( $single_tm_id ) ) {
56 if ( 'elementor_header_footer' === $single_elementor_template ) {
57 $template = HTBUILDER_PL_PATH . 'templates/single-fullwidth.php';
58 } elseif ( 'elementor_canvas' === $single_elementor_template ) {
59 $template = HTBUILDER_PL_PATH . 'templates/single-canvas.php';
60 } else {
61 $template = HTBUILDER_PL_PATH . 'templates/single-fullwidth.php';
62 }
63 }
64
65 // Archive page
66 elseif( ( is_post_type_archive( 'post' ) || htbuilder_is_blog_page() ) && !empty( $archive_tm_id ) ){
67 if ( 'elementor_header_footer' === $archive_elementor_template ) {
68 $template = HTBUILDER_PL_PATH . 'templates/archive-fullwidth.php';
69 } elseif ( 'elementor_canvas' === $archive_elementor_template ) {
70 $template = HTBUILDER_PL_PATH . 'templates/archive-canvas.php';
71 } else {
72 $template = HTBUILDER_PL_PATH . 'templates/archive-fullwidth.php';
73 }
74 }
75
76 return $template;
77
78 }
79
80 /*
81 * Custom Template ID
82 */
83 public function custom_template_id( $option_key ){
84
85 $custom_tm_id = htbuilder_get_option( $option_key, 'htbuilder_templatebuilder_tabs', '0' );
86
87 // Meta value
88 $bltermlayoutid = 0;
89 if( is_category() || is_tag() ){
90 $termobj = get_queried_object();
91 $bltermlayoutid = get_term_meta( $termobj->term_id, 'htbuilder_selectterm_layout', true ) ? get_term_meta( $termobj->term_id, 'htbuilder_selectterm_layout', true ) : '0';
92 }
93 if( $bltermlayoutid != '0' ){
94 $custom_tm_id = $bltermlayoutid;
95 }
96 return $custom_tm_id;
97 }
98
99 /*
100 * Render Elementor single blog content
101 */
102 public function single_blog_content_elementor( $post ) {
103 $templateid = $this->custom_template_id( 'single_blog_page' );
104 if( !empty( $templateid ) ){
105 echo Elementor::instance()->frontend->get_builder_content_for_display( $templateid );
106 }else{
107 the_content();
108 }
109 }
110
111 /*
112 * Render Elementor blog content
113 */
114 public function blog_content_elementor( $post ) {
115 $templateid = $this->custom_template_id( 'archive_blog_page' );
116 if( !empty( $templateid ) ){
117 echo Elementor::instance()->frontend->get_builder_content_for_display( $templateid );
118 }else{
119 the_content();
120 }
121 }
122
123
124 }
125
126 HTBuilder_Custom_Template_Layout::instance();