# Item 5: WordPress Content Template Improvements and Redesign **Priority:** High **Target:** Production Launch **Last Updated:** December 11, 2025 --- ## Overview Redesign WordPress content templates to optimize image placement, content structure, and cluster hub landing pages. Implement adaptive templates for different article lengths (500, 1000, 1500 words) with intelligent image reuse logic and proper HTML formatting. --- ## Current Implementation Analysis ### Content Template System **Location:** `backend/igny8_core/modules/publisher/` and content generation **Current State:** - Content generated as HTML in `Content.content_html` field - Images generated separately with prompts - No formal template system for WordPress publishing - Image placement done during content generation, not during publishing **Issues:** - No consistent image placement strategy - No adaptation for article length - Image reuse logic not implemented - Cluster hub pages not differentiated from regular content --- ### Content HTML Structure **Generated by:** `backend/igny8_core/ai/functions/generate_content.py` **Current Format:** ```html

Hook text...

Introduction paragraph 1...

Introduction paragraph 2...

Section Heading 1

Section content...

Section Heading 2

Section content...

Column 1Column 2
Data 1Data 2
``` **Issues:** - No image tags in HTML (images added separately) - No placeholder markers for image insertion - Section lengths not adaptive to total word count - Table structures sometimes inconsistent --- ### Image System **Models:** - `ContentImage` - Stores image URL, prompt, type (featured/in-article), position - Linked to `Content` via foreign key **Current Image Generation:** 1. Content generated with HTML 2. Image prompts extracted from content 3. Images generated from prompts 4. Images stored in `ContentImage` table 5. Publishing combines content HTML + image URLs **Issues:** - No clear insertion points in HTML - Image position field not always used correctly - Featured image vs in-article distinction unclear - No reuse logic when fewer images than placeholders --- ## Image Placement Strategy ### Placement Rules by Article Length #### 500-Word Article **Structure:** Intro + 2 sections + Conclusion **Image Placement:** - Position 1: After introduction (before first H2) - Position 2: Mid-article (before second H2 or within) - Position 3: Before conclusion (optional, if 3 images available) **Total Images:** 2-3 --- #### 1000-Word Article **Structure:** Intro + 4-5 sections + Conclusion **Image Placement:** - Position 1: After introduction - Position 2: After section 2 - Position 3: After section 3 or 4 (mid-article) - Position 4: Before conclusion - Position 5: Within longest section (optional) **Total Images:** 3-5 --- #### 1500-Word Article **Structure:** Intro + 6-8 sections + Conclusion **Image Placement:** - Position 1: After introduction - Position 2: After section 2 - Position 3: Mid-article (after section 4) - Position 4: After section 5 or 6 - Position 5: Before conclusion - Position 6-7: Within longer sections (optional) **Total Images:** 4-7 --- ### Image Reuse Logic **Scenario:** Not enough images for all placement positions | Available Images | Reuse Strategy | |------------------|----------------| | 1 image | Use 3 times: after intro, mid-article, before conclusion | | 2 images | Alternate: Image 1 → Image 2 → Image 1 → Image 2 (repeat pattern) | | 3 images | Use each twice: distribute evenly across positions | | 4+ images | Use each once until exhausted, then reuse starting from first | **Implementation Logic:** ```python def get_image_for_position(position: int, available_images: list) -> Image: """ Get image for a specific position using reuse logic. Args: position: 0-indexed position (0 = after intro, 1 = mid-article, etc.) available_images: List of ContentImage objects Returns: ContentImage object to use at this position """ if not available_images: return None num_images = len(available_images) if num_images == 1: # Reuse single image everywhere return available_images[0] elif num_images == 2: # Alternate between images return available_images[position % 2] elif num_images == 3: # Use each twice (0,1,2,0,1,2) return available_images[position % 3] else: # Use each once, then repeat return available_images[position % num_images] ``` --- ## Template System Design ### Template Structure **Create:** `backend/igny8_core/modules/publisher/templates.py` (NEW) **Purpose:** Format content + images for WordPress publishing --- ### Base Content Template **Class:** `ContentTemplate` **Methods:** | Method | Purpose | Returns | |--------|---------|---------| | `prepare_content(content, images)` | Main entry point | Formatted HTML | | `insert_images(html, images, word_count)` | Insert images at positions | HTML with images | | `get_image_positions(word_count)` | Calculate insertion points | List of positions | | `format_image_html(image, alt_text)` | Format single image tag | HTML string | | `add_featured_image_meta(content, image)` | Set WordPress featured image | Meta dict | --- ### 500-Word Template **Class:** `ShortFormTemplate(ContentTemplate)` **Structure:** ```html

Hook...

Intro paragraph 1...

Intro paragraph 2...

...
Image caption (optional)

Section Heading 1

Section content...

...

Section Heading 2

Section content...

Conclusion...

``` **Characteristics:** - 2-3 images total - Shorter sections (80-100 words each) - Minimal subsections - Concise lists and tables --- ### 1000-Word Template **Class:** `StandardTemplate(ContentTemplate)` **Structure:** ```html

Hook...

Intro paragraphs...

...

Section Heading 1

Paragraphs...

Subsection 1.1

Content...

Section Heading 2

Content...

...

Section Heading 3

...

Section Heading 4

...
...

Conclusion

Summary and CTA...

``` **Characteristics:** - 3-5 images - Standard sections (140-160 words each) - 2-3 subsections per section - Mix of content types (paragraphs, lists, tables) --- ### 1500-Word Template **Class:** `LongFormTemplate(ContentTemplate)` **Structure:** ```html

Hook (45 words)...

Intro paragraph 1 (70 words)...

Intro paragraph 2 (65 words)...

...

Section Heading 1

Opening paragraph (80 words)...

Subsection 1.1

Content (50 words)...

Subsection 1.2

Content (50 words)...

Section Heading 2

Content...

...

Section Heading 7

Final content section...

...

Conclusion

Summary paragraph...

Call to action...

``` **Characteristics:** - 4-7 images - Longer sections (180-200 words each) - 3-4 subsections per section - Deeper content with more examples - Optional info boxes or callouts --- ## Cluster Hub Landing Page Template **Purpose:** Comprehensive resource page for topic clusters **Class:** `ClusterHubTemplate(ContentTemplate)` ### Structure ```html

{Cluster Name}

{Cluster Description}

...

What is {Cluster Name}?

Comprehensive introduction to the topic...

Why it matters and what you'll learn...

Key Concepts

Concept 1

Brief explanation...

...

Explore Related Topics

Subcluster Name

Description...

Learn more →

Latest Articles

Stay Updated

Get the latest insights on {Cluster Name}...

``` --- ### Cluster Hub Features | Feature | Implementation | Purpose | |---------|----------------|---------| | **Hero Image** | Full-width banner | Visual impact, brand identity | | **Concept Cards** | 3-6 key concepts | Quick overview, scannable | | **Subcluster Grid** | Links to child clusters | Hierarchy navigation | | **Latest Articles** | Auto-query by cluster_id | Fresh content | | **Popular Articles** | Sorted by view_count | Engagement driver | | **CTA Block** | Email signup or action | Lead generation | | **Footer Nav** | Related cluster links | Internal linking | --- ### Conditional Variants #### Category Archive (WordPress Taxonomy) **Differences from Cluster Hub:** - Shows WordPress category tree - Includes post count per category - Pagination for article list - Filter by date, popularity #### Tag Archive **Differences:** - Shows related tags as cloud - Simpler layout (no hero, no concepts) - Focus on article list - Sorted by relevance #### Attribute Archive (Product/Service) **Differences:** - Shows attribute filter options - Product/service grid instead of article list - Comparison table - Filter by attribute values --- ## Implementation Plan ### Phase 1: Template System Foundation (Week 1) **Tasks:** 1. ✅ Create `ContentTemplate` base class 2. ✅ Implement image position calculator 3. ✅ Implement image reuse logic 4. ✅ Create image HTML formatter with figure tags 5. ✅ Add WordPress meta integration (featured image) **File:** `backend/igny8_core/modules/publisher/templates.py` (NEW) --- ### Phase 2: Article Length Templates (Week 1-2) **Tasks:** 1. ✅ Implement `ShortFormTemplate` (500 words) 2. ✅ Implement `StandardTemplate` (1000 words) 3. ✅ Implement `LongFormTemplate` (1500 words) 4. ✅ Test image insertion for each template 5. ✅ Validate HTML output **Testing:** - Generate 10 articles per template - Verify word counts - Check image placement - Validate HTML structure --- ### Phase 3: Cluster Hub Template (Week 2) **Tasks:** 1. ✅ Implement `ClusterHubTemplate` 2. ✅ Create hero section builder 3. ✅ Create concept card generator 4. ✅ Implement article list query 5. ✅ Add related cluster links 6. ✅ Test with real clusters **File:** Same as Phase 1 --- ### Phase 4: Publishing Integration (Week 2-3) **Tasks:** 1. ✅ Update WordPress publisher to use templates 2. ✅ Pass content + images to template 3. ✅ Generate final HTML 4. ✅ Send to WordPress with featured image meta 5. ✅ Test full publishing workflow **File:** `backend/igny8_core/modules/publisher/views.py` **Method:** `publish_to_wordpress()` **Changes:** ```python def publish_to_wordpress(content_id): content = Content.objects.get(id=content_id) images = ContentImage.objects.filter(content=content).order_by('position') # Select template based on word count if content.word_count <= 600: template = ShortFormTemplate() elif content.word_count <= 1200: template = StandardTemplate() else: template = LongFormTemplate() # Prepare content with images final_html = template.prepare_content(content, images) # Get featured image featured_image = images.filter(type='featured').first() # Publish to WordPress wp_client.create_post( title=content.title, content=final_html, featured_image_url=featured_image.image_url if featured_image else None, # ... other meta ) ``` --- ### Phase 5: Taxonomy Templates (Week 3) **Tasks:** 1. ✅ Implement category archive variant 2. ✅ Implement tag archive variant 3. ✅ Implement attribute archive variant 4. ✅ Add conditional rendering logic 5. ✅ Test all taxonomy types --- ## HTML Quality Standards ### Image Tags **Format:** ```html
{descriptive_alt_text}
{optional_caption}
``` **Alt Text Generation:** - Extract from image prompt - Include relevant keywords - Descriptive, not generic ("Person using laptop" → "Digital marketer analyzing SEO metrics on laptop") --- ### Responsive Images (Future) **Enhancement:** ```html {alt_text} ``` **Requires:** Image resizing service or WordPress handling --- ### Content Wrapper **Purpose:** Consistent styling and layout ```html
``` **WordPress Classes:** - `entry-content` - Standard WordPress content class - `wp-block-*` - Gutenberg block classes for proper styling --- ## Testing Requirements ### Template Output Tests | Test Case | Expected Result | |-----------|-----------------| | 500-word article with 1 image | Image reused 3 times at strategic positions | | 1000-word article with 3 images | Each image used once, evenly distributed | | 1500-word article with 5 images | Images at intro, mid-points, and conclusion | | Article with 0 images | No image tags, content flows normally | | Cluster hub page | All sections rendered, related content populated | --- ### HTML Validation - ✅ All HTML valid (W3C validator) - ✅ All image tags have alt text - ✅ Heading hierarchy correct (H1 → H2 → H3) - ✅ No broken image links - ✅ Figure tags properly closed - ✅ WordPress classes applied correctly --- ### WordPress Integration Tests - ✅ Featured image set correctly - ✅ Images appear in correct positions - ✅ Content renders properly in WordPress editor - ✅ Mobile responsive (WordPress theme handles) - ✅ Image captions display correctly - ✅ Internal links work --- ## Success Metrics - ✅ 100% of articles have images placed correctly - ✅ Image reuse logic works for all scenarios - ✅ Article lengths match templates (±5% tolerance) - ✅ HTML validates 100% - ✅ Cluster hubs render all sections - ✅ WordPress publishing succeeds 100% - ✅ User feedback: content looks professional - ✅ No manual image placement needed --- ## Related Files Reference ### Backend (NEW) - `backend/igny8_core/modules/publisher/templates.py` - Template system - `backend/igny8_core/modules/publisher/image_manager.py` - Image reuse logic ### Backend (Update) - `backend/igny8_core/modules/publisher/views.py` - Publishing integration - `backend/igny8_core/ai/functions/generate_content.py` - Content structure ### Models - `backend/igny8_core/business/content/models.py` - Content, ContentImage models --- ## Notes - Templates should be flexible enough for custom themes - Image captions optional (can extract from prompt or leave empty) - Cluster hub template can be used for category/tag pages - Consider adding shortcode support for advanced layouts - Future: Allow custom template selection per content piece - Future: Visual template editor for admins