links) // And: $dog_name, $breed, $age, $weight, $sex, $activity_level, $health_conditions // And: $row['slug'], $row['created_at'], and $db // 1. SEO setup $title_text = "Home-Cooked Recipe for {$dog_name} the {$breed}"; $description_text = "Custom home-cooked recipe for {$dog_name}, a {$age}-year-old {$breed}. Includes protein, fats, vegetables, herbs and step-by-step instructions."; $url = "https://yourdomain.com/recipes/{$row['slug']}.php"; $recipe_jsonld = [ "@context" => "https://schema.org/", "@type" => "Recipe", "name" => $title_text, "description" => $description_text, "author" => ["@type" => "Organization", "name" => "Charlie’s Dog Chow"], "datePublished"=> date("Y-m-d", strtotime($row['created_at'] ?? 'now')), "keywords" => "{$breed}, dog food, homemade dog recipe, {$health_conditions}", "recipeCategory"=> "Dog Food", "recipeYield" => "≈9 lbs", "nutrition" => [ "@type" => "NutritionInformation", "proteinContent" => "~{$desired_protein}%", "fatContent" => "2 oz coconut oil", ], "recipeIngredient"=> [], ]; // 2. Build $aff[]: search term → full affiliate link $aff = []; // Step 1: Load all specific links $stmt = $db->query(" SELECT al.search_term, al.category, ap.base_url, ap.tag FROM affiliate_links al JOIN affiliate_programs ap ON al.program_id = ap.id "); while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $term = strtolower(trim($row['search_term'])); $aff[$term] = htmlspecialchars($row['base_url'] . urlencode($term) . '&tag=' . $row['tag']); } // Step 2: Load fallback defaults for categories $fallback_stmt = $db->query(" SELECT am.product_category, ap.base_url, ap.tag FROM affiliate_mappings am JOIN affiliate_programs ap ON am.program_id = ap.id "); $fallback_links = []; while ($row = $fallback_stmt->fetch(PDO::FETCH_ASSOC)) { $fallback_links[$row['product_category']] = [ 'base_url' => $row['base_url'], 'tag' => $row['tag'] ]; } // Step 3: Populate missing $aff terms from fallback $needed_terms = [ 'coconut oil' => 'oil', 'fresh meat beef' => 'meat', 'carrots' => 'vegetable', 'green beans' => 'vegetable', 'pumpkin' => 'vegetable', 'green peas' => 'vegetable', 'quinoa' => 'grain', 'ginger' => 'herb', 'chamomile' => 'herb', 'kitchen scale' => 'equipment', 'electric pressure cooker' => 'equipment', 'rice cooker' => 'equipment', 'food processor' => 'equipment', 'stand mixer' => 'equipment', 'roasting pan' => 'equipment', 'bpa free food storage containers' => 'equipment', 'bpa free cooking utensils' => 'equipment', ]; foreach ($needed_terms as $term => $category) { $term = strtolower(trim($term)); if (!isset($aff[$term]) && isset($fallback_links[$category])) { $base = $fallback_links[$category]['base_url']; $tag = $fallback_links[$category]['tag']; $aff[$term] = htmlspecialchars($base . urlencode($term) . '&tag=' . $tag); } } ?>