2026-10-04 template-parts/teachers/schema.php
This commit is contained in:
parent
c8a3e68484
commit
01ba1c8dbb
@ -1,59 +1,66 @@
|
||||
<?php
|
||||
|
||||
// Schema.org
|
||||
// Schema.org — листинг педагогов
|
||||
|
||||
if (! defined('ABSPATH')) {
|
||||
exit;
|
||||
}
|
||||
|
||||
$org_name = get_option('branch_name') ?: carbon_get_theme_option('site_name') ?: 'Частная школа «Декарт»';
|
||||
$org_url = home_url('/');
|
||||
$page_url = function_exists('dekart_schema_page_url') ? dekart_schema_page_url() : get_permalink();
|
||||
$org_id = home_url('/') . '#organization';
|
||||
$list_id = $page_url . '#itemlist';
|
||||
|
||||
// Logo
|
||||
$org_logo = '';
|
||||
$branch_logo_id = absint(get_option('branch_logo'));
|
||||
if ($branch_logo_id) {
|
||||
$branch_logo_url = wp_get_attachment_url($branch_logo_id);
|
||||
if ($branch_logo_url) {
|
||||
$org_logo = $branch_logo_url;
|
||||
}
|
||||
$org_name = dekart_branch_option('branch_name') ?: carbon_get_theme_option('site_name') ?: 'Частная школа «Декарт»';
|
||||
$org_phone = dekart_branch_option('branch_phone') ?: carbon_get_theme_option('site_phone') ?: '';
|
||||
$org_logo = function_exists('dekart_resolve_logo') ? dekart_resolve_logo() : '';
|
||||
|
||||
// Адрес — PostalAddress из опций филиала
|
||||
$addr = array( '@type' => 'PostalAddress' );
|
||||
$street = get_option('branch_address') ?: carbon_get_theme_option('site_address') ?: '';
|
||||
$city = dekart_branch_option('branch_city');
|
||||
$region = dekart_branch_option('branch_region');
|
||||
$zip = function_exists('dekart_schema_option') ? dekart_schema_option('schema_postal_code', 'branch_postal_code') : get_option('branch_postal_code');
|
||||
if ($street) {
|
||||
$addr['streetAddress'] = wp_strip_all_tags($street);
|
||||
}
|
||||
if (! $org_logo && carbon_get_theme_option('site_logo')) {
|
||||
$org_logo = wp_get_attachment_url(carbon_get_theme_option('site_logo'));
|
||||
if ($city) {
|
||||
$addr['addressLocality'] = wp_strip_all_tags($city);
|
||||
}
|
||||
if (! $org_logo && carbon_get_theme_option('logo')) {
|
||||
$org_logo = wp_get_attachment_url(carbon_get_theme_option('logo'));
|
||||
if ($region) {
|
||||
$addr['addressRegion'] = wp_strip_all_tags($region);
|
||||
}
|
||||
$org_addr = get_option('branch_address') ?: carbon_get_theme_option('site_address') ?: '';
|
||||
$org_phone = get_option('branch_phone') ?: carbon_get_theme_option('site_phone') ?: '';
|
||||
if (! empty($zip) && is_string($zip)) {
|
||||
$addr['postalCode'] = trim($zip);
|
||||
}
|
||||
$addr['addressCountry'] = 'RU';
|
||||
|
||||
// Ответственные лица
|
||||
$founder_name = get_option('branch_head_name', '');
|
||||
$head_q = get_option('branch_head_position', 'Учредитель школы «Декарт»');
|
||||
$head_q = get_option('branch_head_position', 'Учредитель школы «Декарт»');
|
||||
|
||||
$teachers_schema = array();
|
||||
|
||||
// Руководитель
|
||||
if ($founder_name) {
|
||||
$teachers_schema[] = array(
|
||||
'@type' => 'Person',
|
||||
'name' => $founder_name,
|
||||
'jobTitle' => $head_q ?: 'Учредитель школы «Декарт»',
|
||||
'worksFor' => array( '@type' => 'EducationalOrganization', 'name' => $org_name ),
|
||||
'worksFor' => array( '@id' => $org_id ),
|
||||
);
|
||||
}
|
||||
|
||||
// Педагоги из CPT teacher
|
||||
$schema_args = array(
|
||||
'posts_per_page' => -1,
|
||||
'post_type' => 'teacher',
|
||||
'post_status' => 'publish',
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'no_found_rows' => true,
|
||||
$schema_teachers = get_posts(array(
|
||||
'posts_per_page' => -1,
|
||||
'post_type' => 'teacher',
|
||||
'post_status' => 'publish',
|
||||
'orderby' => 'date',
|
||||
'order' => 'ASC',
|
||||
'no_found_rows' => true,
|
||||
'update_post_meta_cache' => true,
|
||||
);
|
||||
$schema_teachers = get_posts($schema_args);
|
||||
));
|
||||
|
||||
$item_list = array();
|
||||
$position = 0;
|
||||
|
||||
foreach ($schema_teachers as $st) {
|
||||
$tid = (int) $st->ID;
|
||||
@ -61,10 +68,12 @@ foreach ($schema_teachers as $st) {
|
||||
$ed = carbon_get_post_meta($tid, 'teacher_education');
|
||||
$img = carbon_get_post_meta($tid, 'teacher_avatar');
|
||||
|
||||
// Чистый текст, обрезанный для schema description
|
||||
// Чистый текст для schema description
|
||||
$schema_desc = '';
|
||||
if ($ed) {
|
||||
$schema_desc = wp_strip_all_tags($ed);
|
||||
$schema_desc = wp_strip_all_tags((string) $ed);
|
||||
$schema_desc = html_entity_decode($schema_desc, ENT_QUOTES | ENT_HTML5, 'UTF-8');
|
||||
$schema_desc = str_replace(array( "\xC2\xA0", ' ' ), ' ', $schema_desc);
|
||||
$schema_desc = preg_replace('/\s+/u', ' ', $schema_desc);
|
||||
$schema_desc = trim($schema_desc);
|
||||
if (mb_strlen($schema_desc) > 200) {
|
||||
@ -74,10 +83,10 @@ foreach ($schema_teachers as $st) {
|
||||
|
||||
$person = array(
|
||||
'@type' => 'Person',
|
||||
'name' => get_the_title($tid),
|
||||
'name' => wp_strip_all_tags(get_the_title($tid)),
|
||||
'url' => get_permalink($tid),
|
||||
'jobTitle' => $subj ?: 'Преподаватель',
|
||||
'worksFor' => array( '@type' => 'EducationalOrganization', 'name' => $org_name ),
|
||||
'worksFor' => array( '@id' => $org_id ),
|
||||
'description' => $schema_desc,
|
||||
);
|
||||
if ($subj) {
|
||||
@ -86,19 +95,17 @@ foreach ($schema_teachers as $st) {
|
||||
if ($img && wp_get_attachment_url($img)) {
|
||||
$person['image'] = wp_get_attachment_url($img);
|
||||
}
|
||||
// aggregateRating
|
||||
$rating_val = carbon_get_post_meta($tid, 'teacher_rating');
|
||||
$rating_num = is_numeric($rating_val) ? (float) $rating_val : 0.0;
|
||||
$rating_cnt = function_exists('dekart_teacher_review_count') ? dekart_teacher_review_count($tid) : 0;
|
||||
if ($rating_num > 0 && $rating_cnt > 0) {
|
||||
$person['aggregateRating'] = array(
|
||||
'@type' => 'AggregateRating',
|
||||
'ratingValue' => number_format($rating_num, 1),
|
||||
'bestRating' => '5',
|
||||
'ratingCount' => (int) $rating_cnt,
|
||||
);
|
||||
}
|
||||
// aggregateRating НЕ выводим — на листинге нет объектов review
|
||||
|
||||
$teachers_schema[] = $person;
|
||||
|
||||
$position++;
|
||||
$item_list[] = array(
|
||||
'@type' => 'ListItem',
|
||||
'position' => $position,
|
||||
'url' => get_permalink($tid),
|
||||
'name' => wp_strip_all_tags(get_the_title($tid)),
|
||||
);
|
||||
}
|
||||
|
||||
if (empty($teachers_schema)) {
|
||||
@ -106,27 +113,51 @@ if (empty($teachers_schema)) {
|
||||
}
|
||||
|
||||
$org_schema = array(
|
||||
'@type' => 'EducationalOrganization',
|
||||
'name' => $org_name,
|
||||
'url' => $org_url,
|
||||
'@type' => 'EducationalOrganization',
|
||||
'@id' => $org_id,
|
||||
'name' => $org_name,
|
||||
'url' => home_url('/'),
|
||||
'address' => $addr,
|
||||
);
|
||||
if ($org_logo) {
|
||||
$org_schema['logo'] = $org_logo;
|
||||
}
|
||||
if ($org_addr) {
|
||||
$org_schema['address'] = $org_addr;
|
||||
}
|
||||
if ($org_phone) {
|
||||
$org_schema['telephone'] = $org_phone;
|
||||
}
|
||||
$org_schema['employee'] = $teachers_schema;
|
||||
|
||||
$graph = array();
|
||||
|
||||
$collection = array(
|
||||
'@type' => 'CollectionPage',
|
||||
'@id' => $page_url . '#webpage',
|
||||
'url' => $page_url,
|
||||
'name' => wp_strip_all_tags(get_the_title()) ?: 'Преподаватели',
|
||||
);
|
||||
if (! empty($item_list)) {
|
||||
$collection['mainEntity'] = array( '@id' => $list_id );
|
||||
}
|
||||
$graph[] = $collection;
|
||||
|
||||
if (! empty($item_list)) {
|
||||
$graph[] = array(
|
||||
'@type' => 'ItemList',
|
||||
'@id' => $list_id,
|
||||
'name' => 'Преподаватели',
|
||||
'numberOfItems' => count($item_list),
|
||||
'itemListElement' => $item_list,
|
||||
);
|
||||
}
|
||||
|
||||
$graph[] = $org_schema;
|
||||
?>
|
||||
<script type="application/ld+json">
|
||||
<?php echo wp_json_encode(
|
||||
array(
|
||||
'@context' => 'https://schema.org',
|
||||
'@graph' => array( $org_schema ),
|
||||
'@graph' => $graph,
|
||||
),
|
||||
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
|
||||
); ?>
|
||||
</script>
|
||||
</script>
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user