wp content temalpate
This commit is contained in:
137
igny8-wp-plugin/includes/class-igny8-template-loader.php
Normal file
137
igny8-wp-plugin/includes/class-igny8-template-loader.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
/**
|
||||
* IGNY8 Template Loader
|
||||
*
|
||||
* Loads custom template for IGNY8-generated content
|
||||
* Only applies to posts with _igny8_content_id meta field
|
||||
*
|
||||
* @package Igny8Bridge
|
||||
*/
|
||||
|
||||
// Prevent direct access
|
||||
if (!defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
class Igny8_Template_Loader {
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
public function __construct() {
|
||||
// Hook into template loading with high priority
|
||||
add_filter('single_template', [$this, 'load_igny8_template'], 99);
|
||||
|
||||
// Enqueue styles and scripts for IGNY8 template
|
||||
add_action('wp_enqueue_scripts', [$this, 'enqueue_template_assets']);
|
||||
|
||||
// Add body class for IGNY8 content
|
||||
add_filter('body_class', [$this, 'add_body_class']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if current post is IGNY8-generated content
|
||||
*
|
||||
* @param int|null $post_id Post ID (optional, defaults to current post)
|
||||
* @return bool
|
||||
*/
|
||||
public function is_igny8_content($post_id = null) {
|
||||
if (!$post_id) {
|
||||
$post_id = get_the_ID();
|
||||
}
|
||||
|
||||
if (!$post_id) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if post has IGNY8 content ID meta
|
||||
$content_id = get_post_meta($post_id, '_igny8_content_id', true);
|
||||
|
||||
return !empty($content_id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load IGNY8 custom template for IGNY8-generated posts
|
||||
*
|
||||
* @param string $template Default template path
|
||||
* @return string Template path
|
||||
*/
|
||||
public function load_igny8_template($template) {
|
||||
global $post;
|
||||
|
||||
// Only apply to single post views
|
||||
if (!is_singular('post')) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
// Only apply to IGNY8-generated content
|
||||
if (!$this->is_igny8_content($post->ID)) {
|
||||
return $template;
|
||||
}
|
||||
|
||||
// Path to our custom template
|
||||
$custom_template = plugin_dir_path(dirname(__FILE__)) . 'templates/single-igny8-content.php';
|
||||
|
||||
// Use custom template if it exists
|
||||
if (file_exists($custom_template)) {
|
||||
return $custom_template;
|
||||
}
|
||||
|
||||
// Fallback to default template
|
||||
return $template;
|
||||
}
|
||||
|
||||
/**
|
||||
* Enqueue styles and scripts for IGNY8 template
|
||||
*/
|
||||
public function enqueue_template_assets() {
|
||||
global $post;
|
||||
|
||||
// Only enqueue on single post pages
|
||||
if (!is_singular('post')) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Only enqueue for IGNY8 content
|
||||
if (!$this->is_igny8_content($post->ID)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Enqueue custom styles
|
||||
wp_enqueue_style(
|
||||
'igny8-content-template',
|
||||
plugin_dir_url(dirname(__FILE__)) . 'templates/assets/css/igny8-content-template.css',
|
||||
array(),
|
||||
'1.0.0'
|
||||
);
|
||||
|
||||
// Enqueue custom JavaScript (if needed in future)
|
||||
wp_enqueue_script(
|
||||
'igny8-content-template',
|
||||
plugin_dir_url(dirname(__FILE__)) . 'templates/assets/js/igny8-content-template.js',
|
||||
array('jquery'),
|
||||
'1.0.0',
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add body class for IGNY8 content
|
||||
*
|
||||
* @param array $classes Current body classes
|
||||
* @return array Modified body classes
|
||||
*/
|
||||
public function add_body_class($classes) {
|
||||
global $post;
|
||||
|
||||
if (is_singular('post') && $this->is_igny8_content($post->ID)) {
|
||||
$classes[] = 'igny8-content';
|
||||
$classes[] = 'igny8-template-active';
|
||||
}
|
||||
|
||||
return $classes;
|
||||
}
|
||||
}
|
||||
|
||||
// Initialize template loader
|
||||
new Igny8_Template_Loader();
|
||||
Reference in New Issue
Block a user