Skip to content

Instantly share code, notes, and snippets.

@andrei99
Last active August 19, 2020 13:20
Show Gist options
  • Save andrei99/f14f2d0180dbc71e25f8da297fd3783d to your computer and use it in GitHub Desktop.
Save andrei99/f14f2d0180dbc71e25f8da297fd3783d to your computer and use it in GitHub Desktop.
SCHEMA ORG
####### GOOGLE console
https://search.google.com/test/rich-results?utm_campaign=devsite&utm_medium=jsonld&utm_source=article&id=biHfArES8wbgNoMSc0OMFw
$arSchemaOrg = array(
'@context' => 'http://schema.org',
'@type' => 'Article',
'name' => $arResult['NAME'],
'datePublished' => $strDateActive,
'author' => 'person',
'headline' => $arResult['NAME'],
'publisher' => '',
'image' => 'https://' . $_SERVER['SERVER_NAME'] . $arResult['DETAIL_PICTURE']['SRC'],
/*--- dont work by type 'Article'
'aggregateRating' => array(
'@type' => 'AggregateRating',
'ratingValue' => $intRatingValue,
'reviewCount' => $intReviewCount
),
--*/
'publisher' => array(
'@type' => 'Organization',
'name' => $_SERVER['SERVER_NAME'],
'logo' => array(
'@type' => 'ImageObject',
'url' => 'https://semicvetic.com/bitrix/templates/semicvetic_2017/img/logo.png',
'width' => 265,
'height' => 50,
)
)
);
//вывод микроразметки в http://schema.org (json)
$arSchemaOrg = array();
//рейтинг
$intRatingValue = 5;
if ($arResult['ITEM']['RATING'] && is_numeric($arResult['ITEM']['RATING'])){
$intRatingValue = $arResult['ITEM']['RATING'];
}
//отзывы
$intReviewCount = 1;
if ($arResult['ITEM']['COUNT_RATING'] > 0){
$intReviewCount = $arResult['ITEM']['COUNT_RATING'];
}
//цена
$intPriceSchema = 0;
if ($arResult['ITEM']['PRICE']['PERCENT']){
$intPriceSchema = $arResult['ITEM']['PRICE']['DISCOUNT_PRICE'];
}else{
$intPriceSchema = $arResult['ITEM']['PRICE']['BASE_PRICE'];
}
$arSchemaOrg = array(
'@context' => 'http://schema.org',
'@type' => 'Product',
'aggregateRating' => array(
'@type' => 'AggregateRating',
'ratingValue' => $intRatingValue,
'reviewCount' => $intReviewCount,
),
'description' => '',
'name' => $arResult['ITEM']['NAME'],
'image' => '',
'offers' => array(
'@type' => 'Offer',
'availability' => 'http://schema.org/InStock',
'price' => (int)str_replace(' ', '', $intPriceSchema),
'priceCurrency' => 'RUB',
)
);
$arResult['SCHEMA_ORG_PRICE'] = (int)str_replace(' ', '', $intPriceSchema);
$arResult['SCHEMA_ORG'] = $arSchemaOrg;
//вывод микроразметки в http://schema.org (json) --- end
<?//вывод микроразметки в http://schema.org (json) ?>
<? if (!empty($arResult['SCHEMA_ORG'])): ?>
<script type="application/ld+json">
<?= json_encode($arResult['SCHEMA_ORG']) ?>
</script>
<? endif; ?>
//вывод микроразметки в http://schema.org (json)
$arSchemaOrg = array();
//рейтинг
$intRatingValue = 5;
if ($arItem['RATING'] && is_numeric($arItem['RATING'])) {
$intRatingValue = $arItem['RATING'];
}
//отзывы
$intReviewCount = 0;
if ($arItem['COUNT_RATING'] > 0) {
$intReviewCount = $arItem['COUNT_RATING'];
}
//название
$strNameSection = '';
if(!empty($GLOBALS['TITLE_SECTION_SCHEMA'])){
$strNameSection = $GLOBALS['TITLE_SECTION_SCHEMA'];
}else{
$strNameSection = 'Цветы';
}
//количество
$intCountItems = 10;
if(!empty($GLOBALS['ELEMENT_CNT_SCHEMA'])){
$intCountItems = (int)$GLOBALS['ELEMENT_CNT_SCHEMA'];
}
$arSchemaOrg = array(
'@context' => 'http://schema.org',
'@type' => 'Product',
'name' => $strNameSection,
'offers' => array(
'@type' => 'AggregateOffer',
'availability' => 'http://schema.org/InStock',
'itemCondition' => 'http://schema.org/NewCondition',
'lowPrice' => $intPriceOffer['~DISCOUNT_PRICE'],
'priceCurrency' => 'RUB',
'offerCount' => $intCountItems
),
'aggregateRating' => array(
'@type' => 'AggregateRating',
'ratingValue' => $intRatingValue,
'reviewCount' => $intReviewCount
)
);
$arResult['SCHEMA_ORG'] = $arSchemaOrg;
<?//вывод микроразметки в http://schema.org (json) template.php ?>
<? if(!empty($_REQUEST['SECTION_CODE']) && CSite::InDir('/internet-magazin/') && !empty($arResult['SCHEMA_ORG'])): ?>
<script type="application/ld+json">
<?= json_encode($arResult['SCHEMA_ORG']) ?>
</script>
<? endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment