Skip to content

Instantly share code, notes, and snippets.

@hans2103
Last active August 2, 2021 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hans2103/3409d306aac51b79e193c2cb90fb7586 to your computer and use it in GitHub Desktop.
Save hans2103/3409d306aac51b79e193c2cb90fb7586 to your computer and use it in GitHub Desktop.
Structured Data FAQ Page JLayout for Joomla
<?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