Last active
May 7, 2021 13:38
-
-
Save Sentinel-7/1610b03e61a37c69b91c8e97d670cdff to your computer and use it in GitHub Desktop.
application/ld+json
This file contains 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
BreadcrumbList | |
Реализуем с помощью стандартного pdoCrumbs | |
{$_modx->runSnippet('pdoCrumbs',[ | |
'showHome'=> 1, | |
'showCurrent' => 1, | |
'from' => '0' | |
'tplWrapper'=> '@INLINE | |
<script type="application/ld+json"> | |
{ | |
"@context": "http://schema.org", | |
"@type": "BreadcrumbList", | |
"itemListElement": [ {$output} ] | |
} | |
</script>', | |
'tplHome'=>'@INLINE | |
{ | |
"@type": "ListItem", | |
"position": {$idx}, | |
"item": | |
{ | |
"@id": "{$link}", | |
"name": "Главная" | |
} | |
},', | |
'tplCurrent'=>'@INLINE | |
{ | |
"@type": "ListItem", | |
"position": {$idx}, | |
"item": | |
{ | |
"@id": "{$link}", | |
"name": "{$menutitle}" | |
} | |
}', | |
'tpl'=>'@INLINE | |
{ | |
"@type": "ListItem", | |
"position": {$idx}, | |
"item": | |
{ | |
"@id": "{$link}", | |
"name": "{$menutitle}" | |
} | |
},', | |
])} | |
Organization | |
Здесь просто подставляем переменные, обычно я пользуюсь компонентом ClientConfig. | |
{set $organization = [ | |
'@context' => 'https://schema.org', | |
'@type' => 'Organization', | |
'name' => 'company_name' | config, | |
'url' => 'site_url' | config, | |
'logo' => 'site_url' | config ~ 'assets/img/logo.png', | |
'address' => [ | |
'@type' => 'PostalAddress', | |
'streetAddress' => 'address' | config, | |
'addressLocality' => 'city' | config, | |
'postalCode' => 'index' | config, | |
'addressCountry' => 'RU', | |
], | |
'contactPoint' => [ | |
'@type' => 'ContactPoint', | |
'telephone'=> 'phone' | config, | |
'contactType' => 'customer service', | |
'areaServed' => 'RU', | |
'availableLanguage' => 'Russian' | |
] | |
]} | |
<script type="application/ld+json"> | |
{json_encode($organization)} | |
</script> | |
BlogPosting | |
Выводим только на странице статьи. Можно поставить проверку в чанке, на то, какой шаблон. | |
{set $blog_posting = [ | |
'@context' => 'https://schema.org', | |
'@type' => 'BlogPosting', | |
'mainEntityOfPage' =>[ | |
'@type' => 'WebPage', | |
'@id' => $_modx->makeUrl($_modx->resource.id, '','','https') | |
], | |
'headline' => $_modx->resource.pagetitle, | |
'description' => $_modx->resource.description, | |
'image' => 'site_url' | config ~ $_modx->resource.img, | |
'author' =>[ | |
'@type' => 'Organization', | |
'name' => 'company_name' | config | |
], | |
'publisher' =>[ | |
'@type' => 'Organization', | |
'name' => 'company_name' | config, | |
'logo' =>[ | |
'@type' => 'ImageObject', | |
'url' => 'site_url' | config ~ 'assets/img/logo.png' | |
], | |
], | |
'datePublished' => $_modx->resource.publishedon | date_format : '%Y-%m-%d', | |
'dateModified' => $_modx->resource.publishedon | date_format : '%Y-%m-%d', | |
]} | |
<script type="application/ld+json"> | |
{json_encode($blog_posting)} | |
</script> | |
Order | |
{set $order = [ | |
'@context' => 'https://schema.org/', | |
'@type' => 'Order', | |
'seller' => [ | |
'@type' => 'Organization', | |
'name' => 'company_name' | config, | |
'telephone' => 'phone' | config, | |
] | |
]} | |
<script type="application/ld+json"> | |
{json_encode($order)} | |
</script> | |
Product | |
{set $product = [ | |
'@context' => 'https://schema.org', | |
'@type' => 'Product', | |
'description' => 'introtext' | resource, | |
'name' => $page, | |
'image' => 'tv.image_preview' | resource, | |
'offers' => [ | |
'@type' => 'Offer', | |
'availability' => 'https://schema.org/InStock', | |
'price' => 'tv.price' | resource, | |
'priceCurrency' => 'RU' | |
] | |
]} | |
{'!msGallery' | snippet : [ | |
'tpl' => 'tpl.msGallery_new2', | |
'limit' => '1' | |
'toPlaceholder' => 'msimg' | |
]} | |
{if $_modx->resource.template == 3} | |
{set $product = [ | |
'@context' => 'https://schema.org', | |
'@type' => 'Product', | |
'description' => 'introtext' | resource, | |
'name' => $pagetitle, | |
'image' => $_modx->getPlaceholder('msimg'), | |
'offers' => [ | |
'@type' => 'Offer', | |
'availability' => 'https://schema.org/InStock', | |
'price' => $_modx->resource.price, | |
'priceCurrency' => 'RU' | |
] | |
]} | |
<script type="application/ld+json"> | |
{json_encode($product)} | |
</script> | |
Если белый экран, пробуйте так: | |
{set $organization = json_encode($organization) | replace : '{' : '{ '} | |
<script type="application/ld+json"> | |
{$organization} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment