sad
This commit is contained in:
@@ -27,22 +27,25 @@ function igny8_parse_content_sections($content) {
|
||||
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||
libxml_use_internal_errors(true);
|
||||
|
||||
// Load HTML with proper encoding
|
||||
$dom->loadHTML('<?xml encoding="UTF-8">' . $content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
// Wrap content in a div to ensure proper parsing
|
||||
$wrapped_content = '<div>' . $content . '</div>';
|
||||
$dom->loadHTML('<?xml encoding="UTF-8">' . $wrapped_content, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD);
|
||||
libxml_clear_errors();
|
||||
|
||||
$intro_html = '';
|
||||
$sections = [];
|
||||
$current_section = null;
|
||||
|
||||
// Get body node
|
||||
$body = $dom->getElementsByTagName('body')->item(0);
|
||||
if (!$body) {
|
||||
// Get the wrapper div
|
||||
$xpath = new DOMXPath($dom);
|
||||
$nodes = $xpath->query('//div/*');
|
||||
|
||||
if ($nodes->length === 0) {
|
||||
return ['intro' => $content, 'sections' => []];
|
||||
}
|
||||
|
||||
// Iterate through all child nodes
|
||||
foreach ($body->childNodes as $node) {
|
||||
foreach ($nodes as $node) {
|
||||
// Check if node is an H2 heading
|
||||
if ($node->nodeName === 'h2') {
|
||||
// Save previous section if exists
|
||||
|
||||
@@ -51,6 +51,21 @@ $featured_image_prompt = igny8_get_featured_image_prompt(get_the_ID());
|
||||
$content = get_the_content();
|
||||
$content = apply_filters('the_content', $content);
|
||||
$parsed_content = igny8_parse_content_sections($content);
|
||||
|
||||
// Debug logging
|
||||
if (defined('WP_DEBUG') && WP_DEBUG) {
|
||||
error_log('IGNY8 Template Debug - Post ID: ' . get_the_ID());
|
||||
error_log('Content length: ' . strlen($content));
|
||||
error_log('Intro length: ' . strlen($parsed_content['intro']));
|
||||
error_log('Sections count: ' . count($parsed_content['sections']));
|
||||
if (!empty($parsed_content['sections'])) {
|
||||
foreach ($parsed_content['sections'] as $idx => $sec) {
|
||||
error_log('Section ' . ($idx + 1) . ': ' . $sec['heading']);
|
||||
}
|
||||
}
|
||||
error_log('In-article images count: ' . count($in_article_images));
|
||||
error_log('Imported images meta: ' . print_r(get_post_meta(get_the_ID(), '_igny8_imported_images', true), true));
|
||||
}
|
||||
?>
|
||||
|
||||
<div class="igny8-content-wrapper">
|
||||
|
||||
Reference in New Issue
Block a user