From a1393e8b13cb494a27dfdf35c1602e17bb0c4057 Mon Sep 17 00:00:00 2001 From: Turing Date: Thu, 8 Jan 2026 20:53:00 +0300 Subject: [PATCH] add files --- .gitignore | 60 +++++++ arh/partslist.php | 51 ++++++ category.php | 27 +++ footer.php | 25 +++ front-page.php | 22 +++ functions.php | 251 ++++++++++++++++++++++++++++ header.php | 155 +++++++++++++++++ index.php | 0 sidebar.php | 29 ++++ single.php | 64 +++++++ style.css | 3 + tag.php | 27 +++ template-parts/breadcrumbs.php | 43 +++++ template-parts/content-card.php | 59 +++++++ template-parts/content-cards.php | 13 ++ template-parts/current-datetime.php | 28 ++++ template-parts/share-buttons.php | 68 ++++++++ template-parts/subscripts.php | 4 + vite.config.php | 41 +++++ 19 files changed, 970 insertions(+) create mode 100755 .gitignore create mode 100644 arh/partslist.php create mode 100644 category.php create mode 100755 footer.php create mode 100755 front-page.php create mode 100755 functions.php create mode 100755 header.php create mode 100755 index.php create mode 100644 sidebar.php create mode 100644 single.php create mode 100755 style.css create mode 100644 tag.php create mode 100644 template-parts/breadcrumbs.php create mode 100644 template-parts/content-card.php create mode 100644 template-parts/content-cards.php create mode 100644 template-parts/current-datetime.php create mode 100644 template-parts/share-buttons.php create mode 100644 template-parts/subscripts.php create mode 100755 vite.config.php diff --git a/.gitignore b/.gitignore new file mode 100755 index 0000000..e529db9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Зависимости +node_modules/ +vendor/ +bower_components/ + +# Файлы сборки +dist/ +build/ +*.min.js +*.min.css +*.map + +# Исключаем frontend (отдельный репозиторий) +frontend/ + +# Логи +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Переменные окружения +.env +.env.local +.env.*.local + +# Кеш и временные файлы +.sass-cache/ +.cache/ +.tmp/ +*.tmp + +# IDE и редакторы +.vscode/ +.idea/ +*.sublime-project +*.sublime-workspace +*.code-workspace + +# Системные файлы +.DS_Store +Thumbs.db +desktop.ini + +# Файлы базы данных +*.sql +*.sqlite + +# Файлы загрузок (если есть в теме) +uploads/ + +# Composer +composer.lock +composer.phar + +# Package manager lock files (опционально) + package-lock.json + yarn.lock + + diff --git a/arh/partslist.php b/arh/partslist.php new file mode 100644 index 0000000..3e65ef3 --- /dev/null +++ b/arh/partslist.php @@ -0,0 +1,51 @@ +
+

Все новости

+ +
+ +
\ No newline at end of file diff --git a/category.php b/category.php new file mode 100644 index 0000000..da2950e --- /dev/null +++ b/category.php @@ -0,0 +1,27 @@ + + +
+
+

+ + +
+ +
+ +
+ + + + 2, + 'prev_text' => '« Предыдущая', + 'next_text' => 'Следующая »', + )); + ?> +
+ + + diff --git a/footer.php b/footer.php new file mode 100755 index 0000000..285d72a --- /dev/null +++ b/footer.php @@ -0,0 +1,25 @@ +
+ + + + + + + + + \ No newline at end of file diff --git a/front-page.php b/front-page.php new file mode 100755 index 0000000..ec23845 --- /dev/null +++ b/front-page.php @@ -0,0 +1,22 @@ + + +
+
+

Новости спорта

+ +
+ + + +
+ + + + + + + diff --git a/functions.php b/functions.php new file mode 100755 index 0000000..d554368 --- /dev/null +++ b/functions.php @@ -0,0 +1,251 @@ + __( 'Primary Menu', 'my-theme' ), + 'footer-menu' => __( 'Footer Menu', 'my-theme' ) + ) ); + +} +add_action( 'after_setup_theme', 'theme_setup' ); + + +//crops +function my_custom_image_sizes() { + add_image_size( 'small-thumbnail', 300, 200, true ); // Кроп до 300x200 + add_image_size( 'medium-thumbnail', 600, 400, true ); // Кроп до 600x400 + add_image_size( 'large-thumbnail', 1200, 800, true ); // Кроп до 1200x800 +} + +//add_action( 'after_setup_theme', 'my_custom_image_sizes' ); + + +// Создание нового типа записи "Каталог" +function register_catalog_post_type() { + $labels = array( + 'name' => 'Каталог', + 'singular_name' => 'Элемент каталога', + 'menu_name' => 'Каталог', + 'name_admin_bar' => 'Элемент каталога', + 'add_new' => 'Добавить новый', + 'add_new_item' => 'Добавить новый элемент каталога', + 'new_item' => 'Новый элемент каталога', + 'edit_item' => 'Редактировать элемент каталога', + 'view_item' => 'Просмотреть элемент каталога', + 'all_items' => 'Все элементы каталога', + 'search_items' => 'Искать в каталоге', + 'parent_item_colon' => 'Родительский элемент:', + 'not_found' => 'Элементы каталога не найдены.', + 'not_found_in_trash' => 'В корзине элементы каталога не найдены.' + ); + + $args = array( + 'labels' => $labels, + 'public' => true, + 'publicly_queryable' => true, + 'show_ui' => true, + 'show_in_menu' => true, + 'query_var' => true, + 'rewrite' => array('slug' => 'catalog'), + 'capability_type' => 'post', + 'has_archive' => true, + 'hierarchical' => false, + 'menu_position' => 5, + 'menu_icon' => 'dashicons-products', + 'supports' => array('title', 'editor', 'thumbnail', 'excerpt', 'comments', 'custom-fields'), + 'taxonomies' => array('category') // Подключаем стандартные категории + ); + + register_post_type('catalog', $args); +} +add_action('init', 'register_catalog_post_type'); + + + + +function get_first_subcategory( $post_id ) { + // Получаем все категории поста + $categories = get_the_category( $post_id ); + + if ( !empty( $categories ) ) { + // Проходим по каждой категории + foreach ( $categories as $category ) { + // Проверяем, является ли категория подрубрикой (если у неё есть родитель) + if ( $category->parent != 0 ) { + // Возвращаем массив с названием и ссылкой на подрубрику + return array( + 'name' => esc_html( $category->name ), + 'url' => get_category_link( $category->term_id ), + ); + } + } + } + + // Если подрубрика не найдена, возвращаем null + return null; +} + + + +function custom_posts_per_page($query) { + if (!is_admin() && $query->is_main_query()) { + + // Для главной страницы + if (is_home() || is_front_page()) { + $query->set('cat', 174); + $query->set('posts_per_page', 18); + $query->set('post_status', 'publish'); + $query->set('ignore_sticky_posts', 1); + $query->set('meta_query', array( + array( + 'key' => '_thumbnail_id', + 'compare' => 'EXISTS' + ) + )); + } + + // Для архивов рубрик и тегов + if (is_category() || is_tag()) { + $query->set('posts_per_page', 18); + $query->set('meta_query', array( + array( + 'key' => '_thumbnail_id', + 'compare' => 'EXISTS' + ) + )); + } + } +} +add_action('pre_get_posts', 'custom_posts_per_page'); + + +// Добавляем slug категории в body class для архивов и постов +function add_category_slug_to_body_class($classes) { + // Для архивов рубрик + if (is_category()) { + $category = get_queried_object(); + + // Рубрики с обрезкой (cover) - укажите slug нужных рубрик + $cover_categories = array('news'); + + $is_cover = false; + + if (in_array($category->slug, $cover_categories)) { + $is_cover = true; + } + + if (!$is_cover && $category->parent) { + $parent_id = $category->parent; + while ($parent_id) { + $parent = get_category($parent_id); + if (in_array($parent->slug, $cover_categories)) { + $is_cover = true; + break; + } + $parent_id = $parent->parent; + } + } + + if (!$is_cover) { + $classes[] = 'image-portrait'; + } + } + + // Для одиночных постов + if (is_single()) { + $categories = get_the_category(); + + // Рубрики с обрезкой (cover) + $cover_categories = array('news'); + + $is_cover = false; + + foreach ($categories as $category) { + if (in_array($category->slug, $cover_categories)) { + $is_cover = true; + break; + } + + // Проверяем родительские категории + if (!$is_cover && $category->parent) { + $parent_id = $category->parent; + while ($parent_id) { + $parent = get_category($parent_id); + if (in_array($parent->slug, $cover_categories)) { + $is_cover = true; + break; + } + $parent_id = $parent->parent; + } + } + + if ($is_cover) break; + } + + if (!$is_cover) { + $classes[] = 'image-portrait'; + } + } + + return $classes; +} +add_filter('body_class', 'add_category_slug_to_body_class'); + +// Добавляем классы к каждому посту в цикле для архивов тегов +function add_category_class_to_posts($classes, $class, $post_id) { + // Только для архивов тегов + if (is_tag()) { + $categories = get_the_category($post_id); + + // Рубрики с обрезкой (cover) + $cover_categories = array('news'); + + $is_cover = false; + + foreach ($categories as $category) { + if (in_array($category->slug, $cover_categories)) { + $is_cover = true; + break; + } + + // Проверяем родительские категории + if (!$is_cover && $category->parent) { + $parent_id = $category->parent; + while ($parent_id) { + $parent = get_category($parent_id); + if (in_array($parent->slug, $cover_categories)) { + $is_cover = true; + break; + } + $parent_id = $parent->parent; + } + } + + if ($is_cover) break; + } + + if (!$is_cover) { + $classes[] = 'image-portrait'; + } + } + + return $classes; +} +add_filter('post_class', 'add_category_class_to_posts', 10, 3); + + + + + + diff --git a/header.php b/header.php new file mode 100755 index 0000000..2901703 --- /dev/null +++ b/header.php @@ -0,0 +1,155 @@ + +> + + + <?php wp_title('|', true, 'right');?><?=get_bloginfo('name')?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +> + + + + +
+
diff --git a/index.php b/index.php new file mode 100755 index 0000000..e69de29 diff --git a/sidebar.php b/sidebar.php new file mode 100644 index 0000000..415a371 --- /dev/null +++ b/sidebar.php @@ -0,0 +1,29 @@ + \ No newline at end of file diff --git a/single.php b/single.php new file mode 100644 index 0000000..aedc131 --- /dev/null +++ b/single.php @@ -0,0 +1,64 @@ + + +
+ + + + +
> + +
+ + + +

+ +
+ + +
+ + + +
+ +
+ +
+ + +
+ +
+ + + + + +
+ + + + + + +
+ + + + + + \ No newline at end of file diff --git a/style.css b/style.css new file mode 100755 index 0000000..18ce31b --- /dev/null +++ b/style.css @@ -0,0 +1,3 @@ +/* +Theme Name: Sportpressa +*/ \ No newline at end of file diff --git a/tag.php b/tag.php new file mode 100644 index 0000000..e806837 --- /dev/null +++ b/tag.php @@ -0,0 +1,27 @@ + + +
+
+

#

+ + +
+ +
+ +
+ + + + 2, + 'prev_text' => '« Предыдущая', + 'next_text' => 'Следующая »', + )); + ?> +
+ + + diff --git a/template-parts/breadcrumbs.php b/template-parts/breadcrumbs.php new file mode 100644 index 0000000..519179f --- /dev/null +++ b/template-parts/breadcrumbs.php @@ -0,0 +1,43 @@ + ' ) { + $cat = get_category( $cat_id ); + if ( ! $cat ) return; + + // Рекурсивно выводим родителей + if ( $cat->parent != 0 ) { + render_full_category_breadcrumbs( $cat->parent, $position, $separator ); + } + + // Выводим категорию с Schema.org структурой + echo '
  • + + ' . esc_html( $cat->name ) . ' + + +
  • '; + + $position++; +} + +$categories = get_the_category(); +if ( empty( $categories ) ) return; + +$main_cat = $categories[0]; +$breadcrumb_position = 1; +?> + + + + + diff --git a/template-parts/content-card.php b/template-parts/content-card.php new file mode 100644 index 0000000..55d9efe --- /dev/null +++ b/template-parts/content-card.php @@ -0,0 +1,59 @@ + +
    + +
    + + + +
    + + +

    + +

    + + parent != 0) { + $top_parent = get_category($top_parent->parent); + } + + // Выводим родительскую категорию + echo '
    '; + echo ''; + echo ''; + echo esc_html($top_parent->name); + echo ''; + echo ''; + echo '
    '; + } + } else { + // Если это не страница тега, используем существующую логику + $subcategory = get_first_subcategory($post_id); + if ($subcategory) : + ?> +
    + + + + + +
    + +
    + diff --git a/template-parts/content-cards.php b/template-parts/content-cards.php new file mode 100644 index 0000000..14e8580 --- /dev/null +++ b/template-parts/content-cards.php @@ -0,0 +1,13 @@ + +
    + + + +
    + +

    Записей не найдено.

    + diff --git a/template-parts/current-datetime.php b/template-parts/current-datetime.php new file mode 100644 index 0000000..beb87da --- /dev/null +++ b/template-parts/current-datetime.php @@ -0,0 +1,28 @@ + +
    +
    + + 'января', 2 => 'февраля', 3 => 'марта', 4 => 'апреля', + 5 => 'мая', 6 => 'июня', 7 => 'июля', 8 => 'августа', + 9 => 'сентября', 10 => 'октября', 11 => 'ноября', 12 => 'декабря' + ]; + + $days_ru = [ + 0 => 'Воскресенье', 1 => 'Понедельник', 2 => 'Вторник', + 3 => 'Среда', 4 => 'Четверг', 5 => 'Пятница', 6 => 'Суббота' + ]; + + $day = date('j'); + $month = $months_ru[date('n')]; + $year = date('Y'); + $day_name = $days_ru[date('w')]; + $time = date('H:i'); + + echo "$day $month $year, $day_name | Московское время: $time"; + ?> + +
    +
    diff --git a/template-parts/share-buttons.php b/template-parts/share-buttons.php new file mode 100644 index 0000000..8e3499a --- /dev/null +++ b/template-parts/share-buttons.php @@ -0,0 +1,68 @@ + + + diff --git a/template-parts/subscripts.php b/template-parts/subscripts.php new file mode 100644 index 0000000..a4a0f61 --- /dev/null +++ b/template-parts/subscripts.php @@ -0,0 +1,4 @@ +
    Подпишитесь на Спорт  + Дзен + Telegram +
    \ No newline at end of file diff --git a/vite.config.php b/vite.config.php new file mode 100755 index 0000000..993abab --- /dev/null +++ b/vite.config.php @@ -0,0 +1,41 @@ +'; + echo ''; +} + + +add_action( 'wp_enqueue_scripts', function () { + if (defined('VITE_ENV') && VITE_ENV === 'dev') { + add_action( 'wp_head', 'vite_head_module_hook' ); + } else { + + // Production version + $style_ver = filemtime(get_template_directory() . '/frontend/dist/assets/style.css'); + $script_ver = filemtime(get_template_directory() . '/frontend/dist/assets/main.js'); + + wp_enqueue_style('main-style', get_template_directory_uri() . '/frontend/dist/assets/style.css', array(), $style_ver); + wp_enqueue_script('main-script', get_template_directory_uri() . '/frontend/dist/assets/main.js', array(), $script_ver, true); + + } +}); + + + + + +