Image genartiona dn temaplte design redesign
This commit is contained in:
@@ -199,3 +199,156 @@ function igny8_parse_keywords($keywords) {
|
||||
// Remove empty values
|
||||
return array_filter($keywords_array);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get section badges based on keyword/tag matching
|
||||
*
|
||||
* @param string $heading Section heading text
|
||||
* @param int $post_id Post ID
|
||||
* @return array Array of badges with 'text' and 'type' keys
|
||||
*/
|
||||
function igny8_get_section_badges($heading, $post_id) {
|
||||
$badges = [];
|
||||
$heading_lower = strtolower($heading);
|
||||
|
||||
// Get post taxonomies and keywords
|
||||
$tags = get_the_tags($post_id);
|
||||
$categories = get_the_category($post_id);
|
||||
$primary_kw = get_post_meta($post_id, '_igny8_primary_keyword', true);
|
||||
$secondary_kws = get_post_meta($post_id, '_igny8_secondary_keywords', true);
|
||||
|
||||
// Priority 1: Primary keyword
|
||||
if ($primary_kw && stripos($heading_lower, strtolower($primary_kw)) !== false) {
|
||||
$badges[] = ['text' => $primary_kw, 'type' => 'primary'];
|
||||
}
|
||||
|
||||
// Priority 2: Tags
|
||||
if ($tags && !is_wp_error($tags) && count($badges) < 2) {
|
||||
foreach ($tags as $tag) {
|
||||
if (stripos($heading_lower, strtolower($tag->name)) !== false) {
|
||||
$badges[] = ['text' => $tag->name, 'type' => 'tag'];
|
||||
if (count($badges) >= 2) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 3: Categories
|
||||
if ($categories && !is_wp_error($categories) && count($badges) < 2) {
|
||||
foreach ($categories as $cat) {
|
||||
if (stripos($heading_lower, strtolower($cat->name)) !== false) {
|
||||
$badges[] = ['text' => $cat->name, 'type' => 'category'];
|
||||
if (count($badges) >= 2) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Priority 4: Secondary keywords
|
||||
if ($secondary_kws && count($badges) < 2) {
|
||||
$kw_array = is_array($secondary_kws) ? $secondary_kws : explode(',', $secondary_kws);
|
||||
foreach ($kw_array as $kw) {
|
||||
$kw = trim($kw);
|
||||
if (!empty($kw) && stripos($heading_lower, strtolower($kw)) !== false) {
|
||||
$badges[] = ['text' => $kw, 'type' => 'keyword'];
|
||||
if (count($badges) >= 2) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if section content contains a table
|
||||
*
|
||||
* @param string $section_html Section HTML content
|
||||
* @return bool True if contains table
|
||||
*/
|
||||
function igny8_section_has_table($section_html) {
|
||||
return (stripos($section_html, '<table') !== false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get image aspect ratio from position
|
||||
*
|
||||
* @param int $position Image position (0-3)
|
||||
* @return string 'square' or 'landscape'
|
||||
*/
|
||||
function igny8_get_image_aspect($position) {
|
||||
// Even positions (0, 2) = square
|
||||
// Odd positions (1, 3) = landscape
|
||||
return ($position % 2 === 0) ? 'square' : 'landscape';
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if image description should be shown
|
||||
*
|
||||
* @param int $section_index Section index (0-based)
|
||||
* @return bool True if should show description
|
||||
*/
|
||||
function igny8_show_image_description($section_index) {
|
||||
// First 4 sections (0-3) show descriptions
|
||||
return ($section_index < 4);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate table of contents from content
|
||||
*
|
||||
* @param string $content HTML content
|
||||
* @return array Array of TOC items with 'number', 'text', and 'id' keys
|
||||
*/
|
||||
function igny8_generate_table_of_contents($content) {
|
||||
$toc_items = [];
|
||||
|
||||
// Parse content for H2 headings
|
||||
preg_match_all('/<h2[^>]*>(.*?)<\/h2>/i', $content, $matches);
|
||||
|
||||
if (!empty($matches[1])) {
|
||||
foreach ($matches[1] as $index => $heading) {
|
||||
$heading_text = strip_tags($heading);
|
||||
$slug = sanitize_title($heading_text);
|
||||
$toc_items[] = [
|
||||
'number' => $index + 1,
|
||||
'text' => $heading_text,
|
||||
'id' => $slug
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
return $toc_items;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render widget placeholder
|
||||
*
|
||||
* @param string $position 'left' or 'right'
|
||||
* @param int $section_index Section index
|
||||
* @return void
|
||||
*/
|
||||
function igny8_render_widget_placeholder($position, $section_index) {
|
||||
// Check if widgets are enabled in settings
|
||||
$widgets_enabled = get_option('igny8_widgets_enabled', false);
|
||||
|
||||
if (!$widgets_enabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
$placeholder_class = 'igny8-widget-placeholder igny8-widgets-enabled';
|
||||
$placeholder_class .= ' igny8-widget-' . $position;
|
||||
$placeholder_class .= ' igny8-widget-section-' . $section_index;
|
||||
|
||||
?>
|
||||
<div class="<?php echo esc_attr($placeholder_class); ?>"
|
||||
data-widget-position="<?php echo esc_attr($position); ?>"
|
||||
data-section-index="<?php echo esc_attr($section_index); ?>">
|
||||
<?php
|
||||
/**
|
||||
* Action hook for widget placeholder content
|
||||
*
|
||||
* @param string $position Widget position (left/right)
|
||||
* @param int $section_index Section index
|
||||
*/
|
||||
do_action('igny8_widget_placeholder', $position, $section_index);
|
||||
?>
|
||||
</div>
|
||||
<?php
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user