LR
← Back to projects

Dynamic job profiles (WordPress).

WordPress template that generates 50+ FR/EN job profiles from structured JSON, with robust rendering on variable content.

wordpressphpjsonhtmlcss
Dynamic job profiles (WordPress)

Challenges

  1. 01.Industrialize the generation of 50+ profiles from heterogeneous structures
  2. 02.Handle multilingual (FR/EN) and consistent slugs / URLs
  3. 03.Guarantee clean rendering even when some sections are missing (incomplete data)
  4. 04.Keep editing maintainable: content in the JSON, display in the template

Solutions

  1. 01.PHP template split into blocks (missions, skills, training, CTA, etc.) fed by JSON
  2. 02.Fallback system: section hidden if empty, default values, centralized labels (common.json)
  3. 03.FR/EN slug mapping for stable URLs and consistent translation links
  4. 04.Shared content (e.g. contacts) referenced by ID to avoid duplication
JSON loading + conditional rendering (no ACF)php
1// Déterminer la langue (ex : via WPML/Polylang ou une règle maison)
2 $lang = function_exists('pll_current_language') ? pll_current_language('slug') : 'fr';
3
4 // Exemple : URL -> .../marketing-communication/analyste-cybersecurite/
5 // $category_slug et $job_slug proviennent du routage/template
6 $category_slug = get_query_var('category_slug');
7 $job_slug = get_query_var('job_slug');
8
9 // Charger le JSON de la catégorie (fr/categories/<slug>.json)
10 $json_path = get_stylesheet_directory() . "/fiches-metiers/{$lang}/categories/{$category_slug}.json";
11 $items = file_exists($json_path) ? json_decode(file_get_contents($json_path), true) : [];
12
13 // Retrouver la fiche par slug
14 $job = null;
15 foreach ($items as $item) {
16 if (($item['slug'] ?? '') === $job_slug) {
17 $job = $item;
18 break;
19 }
20 }
21 if (!$job) {
22 // 404 si fiche introuvable
23 status_header(404);
24 nocache_headers();
25 include get_404_template();
26 exit;
27 }
28
29 // Exemple : rendre une section uniquement si la donnée existe
30 $skills = $job['competences_block']['items'] ?? [];
31 if (!empty($skills)) : ?>
32 <section class="job-section">
33 <h2>Compétences clés</h2>
34 <ul>
35 <?php foreach ($skills as $skill) : ?>
36 <li><?php echo esc_html($skill); ?></li>
37 <?php endforeach; ?>
38 </ul>
39 </section>
40 <?php endif; ?>
→ NextOther projects
Dynamic job profiles (WordPress) | Louis Rotellini