templates = [ 'layerslider-blank' => [ 'path' => LS_ROOT_PATH.'/views/template-blank.php', 'label' => 'LayerSlider Blank Template' ] ]; // Add our templates to the page template dropdown add_filter( 'theme_page_templates', [ $this, 'add_templates' ], 10, 3 ); add_filter( 'theme_post_templates', [ $this, 'add_templates' ], 10, 3 ); // Add metabox to the page editor for custom settings add_action( 'add_meta_boxes', [ $this, 'add_meta_box' ], 10, 0 ); add_action( 'save_post', [ $this, 'save_meta_box' ], 10, 1 ); // Load our templates add_filter( 'template_include', [ $this, 'load_templates' ], 10, 1 ); } public function add_templates( $templates, $theme, $post ) { foreach( $this->templates as $key => $item ) { $templates[ $key ] = $item['label']; } return $templates; } public function load_templates( $template ) { global $post; if( ! $post ) { return $template; } $page_template_slug = get_page_template_slug( $post->ID ); if( isset( $this->templates[ $page_template_slug ] ) ){ return $this->templates[ $page_template_slug ]['path']; } return $template; } public function add_meta_box() { add_meta_box( 'ls-page-meta-box', __( 'LayerSlider', 'LayerSlider' ), [ $this, 'render_meta_box' ], [ 'post', 'page' ], 'side', 'high' ); } public function render_meta_box( $post ) { $keys = get_post_custom_keys( $post->ID ); $keys = ! empty( $keys ) ? $keys : []; $center = boolval( get_post_meta( $post->ID, 'ls-center-content', true ) ); $center = ! in_array( 'ls-center-content', $keys ) ? true : $center; $background = get_post_meta( $post->ID, 'ls-page-background', true ); $background = ! empty( $background ) ? $background : '#ffffff'; wp_nonce_field( 'ls-page-meta-box', 'ls-page-meta-box-nonce' ); ?>
page_template === 'layerslider-blank' ? 'checked' : '' ?>>
>