Last active
August 2, 2021 14:58
-
-
Save hans2103/3409d306aac51b79e193c2cb90fb7586 to your computer and use it in GitHub Desktop.
Structured Data FAQ Page JLayout for Joomla
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('_JEXEC') or die; | |
/** | |
* Example implementation | |
* | |
* $data = array(); | |
* foreach ($this->item->faqs as $key => $faq) | |
* { | |
* $data[$key]['question'] = $faq->title; | |
* $data[$key]['answer'] = htmlspecialchars_decode($faq->description); | |
* } | |
* echo LayoutHelper::render('data-type.faqpage', $data); | |
*/ | |
if (!empty($displayData)) | |
{ | |
echo '<script type="application/ld+json">'; | |
$data = [ | |
'@context' => "https://schema.org", | |
'@type' => "FAQPage", | |
'mainEntity' => [] | |
]; | |
foreach ($displayData as $key => $faq) | |
{ | |
$data['mainEntity'][] = array( | |
'@type' => "Question", | |
'name' => $faq['question'], | |
'acceptedAnswer' => array( | |
'@type' => "Answer", | |
'text' => htmlspecialchars_decode($faq['answer']) | |
) | |
); | |
} | |
echo json_encode($data); | |
echo '</script>'; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment