Site Builder
Editing:
faq.php
writable 0666
<?php /************************************************************************** * FAQ FRONT‑END – /faqs/faq.php (all‑in‑one, cache‑friendly) * ---------------------------------------------------------------------- * • Reads faqs.json in the same folder * • Outputs an accordion + <script type="application/ld+json"> FAQPage * • No external assets, no JS frameworks **************************************************************************/ $dir = __DIR__; $file = $dir.'/faqs.json'; $data = is_readable($file) ? json_decode(file_get_contents($file), true) : []; $cats = $data['categories'] ?? []; if (!$cats) { echo '<p style="text-align:center">No FAQs yet.</p>'; return; } /* ---------- build FAQPage schema --------- */ $items = []; foreach ($cats as $c) foreach ($c['faqs'] as $f) $items[] = [ "@type"=>"Question", "name"=>$f['q'], "acceptedAnswer"=>["@type"=>"Answer","text"=>$f['a']] ]; $schema = [ "@context"=>"https://schema.org", "@type"=>"FAQPage", "mainEntity"=>$items ]; ?><!doctype html> <meta charset="utf-8"> <title>FAQs</title> <meta name=viewport content="width=device-width,initial-scale=1"> <style> :root{--b:#0066ff;--bg:#f5f7fc;--fg:#111} *{box-sizing:border-box;font-family:system-ui,Arial,sans-serif} body{margin:0;background:var(--bg);color:var(--fg)} h1{text-align:center;margin:2rem 0 1rem;font-size:1.9rem} .faq-cat{margin:1.8rem auto;max-width:760px;padding:0 1rem} .faq-cat h2{font-size:1.4rem;margin:0 0 .7rem;color:#003c9e} .q-wrap{border:1px solid #d3ddf1;border-radius:9px;margin:.6rem 0;overflow:hidden} .q-head{background:#eff3ff;padding:.9rem 1rem;cursor:pointer;font-weight:600} .q-icon{float:right;transition:.25s} .q-body{display:none;padding:1rem;background:#fff} .open .q-body{display:block} .open .q-icon{transform:rotate(180deg)} @media(prefers-color-scheme:dark){ body{--bg:#0d1117;--fg:#e6edf3} .q-head{background:#162147} .q-wrap{border-color:#354675} } </style> <h1>Frequently Asked Questions</h1> <?php foreach($cats as $cid=>$c): ?> <section class="faq-cat"> <h2><?= htmlspecialchars($c['title']) ?></h2> <?php foreach($c['faqs'] as $qid=>$f): $id="c$cid"."q$qid"; ?> <div class="q-wrap" id="<?= $id ?>"> <div class="q-head" onclick="this.parentNode.classList.toggle('open')"> <?= htmlspecialchars($f['q']) ?> <span class="q-icon">▼</span> </div> <div class="q-body"><?= nl2br(htmlspecialchars($f['a'])) ?></div> </div> <?php endforeach ?> </section> <?php endforeach ?> <script type="application/ld+json"><?= json_encode($schema, JSON_UNESCAPED_SLASHES|JSON_UNESCAPED_UNICODE) ?></script>
Save changes
Create folder
writable 0777
Create
Cancel