118 lines
4.8 KiB
PHP
118 lines
4.8 KiB
PHP
<?php
|
|
/**
|
|
* IGNY8 Content Sections
|
|
* Parses content HTML and displays sections with in-article images
|
|
*
|
|
* @package Igny8Bridge
|
|
*/
|
|
|
|
// Exit if accessed directly
|
|
if (!defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
?>
|
|
|
|
<div class="igny8-content-body">
|
|
|
|
<!-- Introduction (content before first H2) -->
|
|
<?php if (!empty($parsed_content['intro'])): ?>
|
|
<section class="igny8-intro-section">
|
|
<div class="igny8-section-label">Opening Narrative</div>
|
|
<div class="igny8-prose">
|
|
<?php echo $parsed_content['intro']; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
<!-- H2 Sections with Images -->
|
|
<?php if (!empty($parsed_content['sections'])): ?>
|
|
<?php foreach ($parsed_content['sections'] as $index => $section): ?>
|
|
<section class="igny8-content-section" id="<?php echo esc_attr($section['id']); ?>">
|
|
<div class="igny8-section-container">
|
|
|
|
<div class="igny8-section-header">
|
|
<span class="igny8-section-number"><?php echo $index + 1; ?></span>
|
|
<div class="igny8-section-heading-wrapper">
|
|
<span class="igny8-section-label">Section Spotlight</span>
|
|
<h2 class="igny8-section-heading"><?php echo esc_html($section['heading']); ?></h2>
|
|
</div>
|
|
</div>
|
|
|
|
<?php
|
|
// Get image for this section (position = section index + 1)
|
|
$section_position = $index + 1;
|
|
|
|
// Try multiple sources for in-article images
|
|
$img_data = null;
|
|
$img_url = null;
|
|
$img_prompt = '';
|
|
|
|
// Source 1: From $in_article_images array
|
|
if (isset($in_article_images[$section_position])) {
|
|
$img_data = $in_article_images[$section_position];
|
|
if (isset($img_data['attachment_id'])) {
|
|
$img_url = wp_get_attachment_image_url($img_data['attachment_id'], 'large');
|
|
$img_prompt = isset($img_data['prompt']) ? $img_data['prompt'] : '';
|
|
} elseif (isset($img_data['url'])) {
|
|
$img_url = $img_data['url'];
|
|
$img_prompt = isset($img_data['prompt']) ? $img_data['prompt'] : '';
|
|
}
|
|
}
|
|
|
|
// Source 2: Check gallery images meta
|
|
if (!$img_url) {
|
|
$gallery = get_post_meta(get_the_ID(), '_igny8_gallery_images', true);
|
|
if ($gallery && is_array($gallery) && isset($gallery[$index])) {
|
|
$img_url = wp_get_attachment_image_url($gallery[$index], 'large');
|
|
}
|
|
}
|
|
|
|
$has_image = !empty($img_url);
|
|
?>
|
|
|
|
<div class="igny8-section-content<?php echo $has_image ? ' igny8-has-image' : ''; ?>">
|
|
<div class="igny8-section-text">
|
|
<div class="igny8-prose">
|
|
<?php echo $section['content']; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<?php if ($has_image):
|
|
$img_alt = '';
|
|
if (isset($img_data['attachment_id'])) {
|
|
$img_alt = get_post_meta($img_data['attachment_id'], '_wp_attachment_image_alt', true);
|
|
}
|
|
?>
|
|
<div class="igny8-section-image">
|
|
<figure class="igny8-image-figure">
|
|
<img src="<?php echo esc_url($img_url); ?>"
|
|
alt="<?php echo esc_attr($img_alt ?: $section['heading']); ?>"
|
|
class="igny8-in-article-image"
|
|
loading="lazy">
|
|
<?php if ($img_prompt): ?>
|
|
<figcaption class="igny8-image-caption">
|
|
<p class="igny8-caption-label">Visual Direction</p>
|
|
<p class="igny8-caption-text"><?php echo esc_html($img_prompt); ?></p>
|
|
</figcaption>
|
|
<?php endif; ?>
|
|
</figure>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
|
|
</div>
|
|
</section>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
|
|
<!-- Fallback: If no sections parsed, show content as-is -->
|
|
<?php if (empty($parsed_content['intro']) && empty($parsed_content['sections'])): ?>
|
|
<section class="igny8-content-fallback">
|
|
<div class="igny8-prose">
|
|
<?php echo $content; ?>
|
|
</div>
|
|
</section>
|
|
<?php endif; ?>
|
|
|
|
</div>
|