functions.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. if ( ! defined( '_S_VERSION' ) ) {
  3. // Replace the version number of the theme on each release.
  4. define( '_S_VERSION', '1.0.0' );
  5. }
  6. function ggpromarket_init(){
  7. register_post_type( 'catalog', [
  8. 'label' => null,
  9. 'labels' => [
  10. 'name' => 'Каталог', // основное название для типа записи
  11. 'singular_name' => 'Каталог', // название для одной записи этого типа
  12. 'add_new' => 'Добавить новый шаблон', // для добавления новой записи
  13. 'add_new_item' => 'Добавление шаблона', // заголовка у вновь создаваемой записи в админ-панели.
  14. 'edit_item' => 'Редактирование шаблона', // для редактирования типа записи
  15. 'new_item' => 'Новый шаблон', // текст новой записи
  16. 'view_item' => 'Смотреть шаблон страницы', // для просмотра записи этого типа.
  17. 'search_items' => 'Искать шаблон в каталоге', // для поиска по этим типам записи
  18. 'not_found' => 'Не найдено', // если в результате поиска ничего не было найдено
  19. 'not_found_in_trash' => 'Не найдено в корзине', // если не было найдено в корзине
  20. 'parent_item_colon' => '', // для родителей (у древовидных типов)
  21. 'menu_name' => 'Каталог', // название меню
  22. ],
  23. 'description' => '',
  24. 'public' => true,
  25. 'menu_icon' => 'dashicons-beer',
  26. 'hierarchical' => false,
  27. 'supports' => [ 'title', 'editor', 'thumbnail', 'excerpt', 'post-formats', 'revisions','page-attributes'], // 'title','editor','author','thumbnail','excerpt','trackbacks','custom-fields','comments','revisions','page-attributes','post-formats'
  28. 'taxonomies' => [],
  29. 'has_archive' => false,
  30. 'menu_position' => 4,
  31. ] );
  32. }
  33. function ggpromarket_setup() {
  34. /*
  35. * Make theme available for translation.
  36. * Translations can be filed in the /languages/ directory.
  37. * If you're building a theme based on GGPromarket, use a find and replace
  38. * to change 'ggpromarket' to the name of your theme in all the template files.
  39. */
  40. load_theme_textdomain( 'ggpromarket', get_template_directory() . '/languages' );
  41. // Add default posts and comments RSS feed links to head.
  42. add_theme_support( 'automatic-feed-links' );
  43. /*
  44. * Let WordPress manage the document title.
  45. * By adding theme support, we declare that this theme does not use a
  46. * hard-coded <title> tag in the document head, and expect WordPress to
  47. * provide it for us.
  48. */
  49. add_theme_support( 'title-tag' );
  50. /*
  51. * Enable support for Post Thumbnails on posts and pages.
  52. *
  53. * @link https://developer.wordpress.org/themes/functionality/featured-images-post-thumbnails/
  54. */
  55. add_theme_support( 'post-thumbnails' );
  56. /*
  57. * Switch default core markup for search form, comment form, and comments
  58. * to output valid HTML5.
  59. */
  60. add_theme_support(
  61. 'html5',
  62. array(
  63. 'search-form',
  64. 'comment-form',
  65. 'comment-list',
  66. 'gallery',
  67. 'caption',
  68. 'style',
  69. 'script',
  70. )
  71. );
  72. // Set up the WordPress core custom background feature.
  73. add_theme_support(
  74. 'custom-background',
  75. apply_filters(
  76. 'ggpromarket_custom_background_args',
  77. array(
  78. 'default-color' => 'ffffff',
  79. 'default-image' => '',
  80. )
  81. )
  82. );
  83. // Add theme support for selective refresh for widgets.
  84. add_theme_support( 'customize-selective-refresh-widgets' );
  85. /**
  86. * Add support for core custom logo.
  87. *
  88. * @link https://codex.wordpress.org/Theme_Logo
  89. */
  90. add_theme_support(
  91. 'custom-logo',
  92. array(
  93. 'height' => 250,
  94. 'width' => 250,
  95. 'flex-width' => true,
  96. 'flex-height' => true,
  97. )
  98. );
  99. add_theme_support('post-formats',array('aside','gallery'));
  100. register_nav_menu('header-menu','Навигация в шапке сайта');
  101. }
  102. function ggpromarket_scripts() {
  103. $prefix_name = "ggpromarket";
  104. wp_enqueue_style( $prefix_name . '-style', get_template_directory_uri() . '/assets/css/Style.css', false, _S_VERSION );
  105. wp_enqueue_script( $prefix_name . '-form', get_template_directory_uri() . '/assets/js/Form.js', false, _S_VERSION, true );
  106. wp_enqueue_script( $prefix_name . '-script', get_template_directory_uri() . '/assets/js/Script.js', false, _S_VERSION, true );
  107. wp_enqueue_script( $prefix_name . '-map', get_template_directory_uri() . '/assets/js/Map.js', false, _S_VERSION, true );
  108. wp_enqueue_script( $prefix_name . '-modal', get_template_directory_uri() . '/assets/js/Modal.js', false, _S_VERSION, true );
  109. }
  110. /**
  111. * Fix pagination on archive pages
  112. * After adding a rewrite rule, go to Settings > Permalinks and click Save to flush the rules cache
  113. *
  114. * Прим разработчика:
  115. * Нельзя делать редирект нга ту же страницу, иначе пермалинки начигают захлебываться
  116. */
  117. function my_pagination_rewrite() {
  118. add_rewrite_rule('catalog/page/?([0-9]{1,})/?$', 'index.php?page_id=90&paged=$matches[1]', 'top');
  119. }
  120. add_action('init', 'my_pagination_rewrite',1);
  121. add_action( 'after_setup_theme', 'ggpromarket_setup' );
  122. add_action( 'wp_enqueue_scripts', 'ggpromarket_scripts' );
  123. add_action( 'init', 'ggpromarket_init',2);