108 lines
3.6 KiB
PHP
108 lines
3.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Преподаватели — Schema.org: EducationalOrganization + Person[]
|
|
* Person: имя, url, jobTitle (направление), image, worksFor, description,
|
|
* alumniOf/education, knowsAbout, опционально review (rating).
|
|
*
|
|
* @package Dekart
|
|
*/
|
|
|
|
if (! defined('ABSPATH')) {
|
|
exit;
|
|
}
|
|
|
|
$org_name = get_option('branch_name') ?: carbon_get_theme_option('site_name') ?: 'Частная школа «Декарт»';
|
|
$org_url = home_url('/');
|
|
$org_logo = carbon_get_theme_option('logo') ? wp_get_attachment_url(carbon_get_theme_option('logo')) : '';
|
|
$org_addr = get_option('branch_address') ?: carbon_get_theme_option('site_address') ?: '';
|
|
$org_phone = get_option('branch_phone') ?: carbon_get_theme_option('site_phone') ?: '';
|
|
|
|
// ─── Ответственные лица для schema (CF на странице можно добавить позже) ───
|
|
$founder_name = get_option('branch_head_name', '');
|
|
$head_q = get_option('branch_head_position', 'Учредитель школы «Декарт»');
|
|
|
|
$teachers_schema = array();
|
|
|
|
// Руководитель (если задан) — как Person/Founder внутри организации
|
|
if ($founder_name) {
|
|
$teachers_schema[] = array(
|
|
'@type' => 'Person',
|
|
'name' => $founder_name,
|
|
'jobTitle' => $head_q ?: 'Учредитель школы «Декарт»',
|
|
'worksFor' => array( '@type' => 'EducationalOrganization', 'name' => $org_name ),
|
|
);
|
|
}
|
|
|
|
// Педагоги из CPT teacher
|
|
$schema_args = 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);
|
|
|
|
foreach ($schema_teachers as $st) {
|
|
$tid = (int) $st->ID;
|
|
$subj = carbon_get_post_meta($tid, 'teacher_direction');
|
|
$ed = carbon_get_post_meta($tid, 'teacher_education');
|
|
$img = carbon_get_post_meta($tid, 'teacher_avatar');
|
|
|
|
// Чистый текст, обрезанный для schema description
|
|
$schema_desc = '';
|
|
if ($ed) {
|
|
$schema_desc = wp_strip_all_tags($ed);
|
|
$schema_desc = preg_replace('/\s+/u', ' ', $schema_desc);
|
|
$schema_desc = trim($schema_desc);
|
|
if (mb_strlen($schema_desc) > 200) {
|
|
$schema_desc = mb_substr($schema_desc, 0, 197) . '…';
|
|
}
|
|
}
|
|
|
|
$person = array(
|
|
'@type' => 'Person',
|
|
'name' => get_the_title($tid),
|
|
'url' => get_permalink($tid),
|
|
'jobTitle' => $subj ?: 'Преподаватель',
|
|
'worksFor' => array( '@type' => 'EducationalOrganization', 'name' => $org_name ),
|
|
'description' => $schema_desc,
|
|
);
|
|
if ($img && wp_get_attachment_url($img)) {
|
|
$person['image'] = wp_get_attachment_url($img);
|
|
}
|
|
$teachers_schema[] = $person;
|
|
}
|
|
|
|
if (empty($teachers_schema)) {
|
|
return;
|
|
}
|
|
|
|
$org_schema = array(
|
|
'@type' => 'EducationalOrganization',
|
|
'name' => $org_name,
|
|
'url' => $org_url,
|
|
);
|
|
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;
|
|
?>
|
|
<script type="application/ld+json">
|
|
<?php echo wp_json_encode(
|
|
array(
|
|
'@context' => 'https://schema.org',
|
|
'@graph' => array( $org_schema ),
|
|
),
|
|
JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT
|
|
); ?>
|
|
</script>
|