Skip to content

Instantly share code, notes, and snippets.

@Edarlingen
Last active November 12, 2020 21:02
Show Gist options
  • Save Edarlingen/0ef91b039b5d7a08308e to your computer and use it in GitHub Desktop.
Save Edarlingen/0ef91b039b5d7a08308e to your computer and use it in GitHub Desktop.
Установка Title в NetCat
<?php
function get_seo_title($title_delimeter = ' :: ') {
global $parent_sub_tree;
global $current_sub;
global $current_cc;
global $action;
global $message;
global $title_tail;
$nc_core = nc_Core::get_object();
$title = $nc_core->page->get_title();
$seo_title = '';
# Для раздела задан уникальный Title?
if ($title) {
# Задан. Используем уникальный Title (Выбор объекта -> Дополнительно -> Заголовок страницы).
$seo_title = $title;
}
# Уникальный Title не задан
else {
# Перебор родительских разделов
for($i = count($parent_sub_tree) - 1; $i >= 1; --$i) {
$seo_title .= $parent_sub_tree[$i]['Subdivision_Name'] . $title_delimeter;
}
# Текущий раздел
$seo_title .= $current_sub['Subdivision_Name'];
# Текущий раздел, на странице объекта
if ($action === 'full') {
# Cобираем информацию о текущем объекте
$current_object = $nc_core->message->get_by_id($current_cc['Class_ID'], $message);
# Ищем информацию для формирования Title в полях Title, PageTitle и Name, если такие есть
if ($current_object['Title']) {
$object_title = $current_object['Title'];
}
if ($current_object['PageTitle']) {
$object_title = $current_object['PageTitle'];
}
if ($current_object['Name']) {
$object_title = $current_object['Name'];
}
# Если Title объекту сформировать удалось, то добавляем его в хвост
$seo_title .= ($object_title ? $title_delimeter . $object_title : null);
}
}
if ($title_tail) {
$seo_title .= $title_tail;
}
return $seo_title;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment