среда, 1 марта 2017 г.

Создание теммы

1)
 темму тут брать
http://underscores.me/

2)
подключаем настройки
add_filter( 'ot_theme_mode', '__return_true' );
//add_filter( 'ot_show_pages', '__return_false' );
//add_filter( 'ot_show_new_layout', '__return_false' );
//add_filter( 'ot_post_formats', '__return_true' );


require( trailingslashit( get_template_directory() ) . 'option-tree/ot-loader.php' );



***************************************************************
шаблон страницы
<?php /* Template Name: Example Template */ ?>

*****************************************************
удаление категории в названии



add_filter( 'get_the_archive_title', function ($title) {

    if ( is_category() ) {

            $title = single_cat_title( '', false );

        } elseif ( is_tag() ) {

            $title = single_tag_title( '', false );

        } elseif ( is_author() ) {

            $title = '<span class="vcard">' . get_the_author() . '</span>' ;

        }

    return $title;

});
******************************************************************************
меню
1)Walker_Nav_Menu
https://developer.wordpress.org/reference/classes/walker_nav_menu/
1)хук для  добавления  класса к ссылке
  http://hookr.io/filters/nav_menu_link_attributes/

  //класc для тега a
function filter_nav_menu_link_attributes( $atts, $item, $args, $depth ) {
    if (array_search("current-menu-item",$item->classes)) {
       $atts['class']='main-menu_item_link active';
    } else {
       $atts['class']='main-menu_item_link';
    }
    return $atts;
};
add_filter( 'nav_menu_link_attributes', 'filter_nav_menu_link_attributes', 10, 4 );


******************************************************************************
Перенос
1)созданные типы постов с помощью  CPT UI экспортировать в php
    экспортировать и подключить в темме
2)ACF- тоже самое
    но тут проблемма дубликаты(пробовать разобраться)
3)option-tree экспортировать и подключить в темме

************************************************
// убираем мусор из шапки
remove_action('wp_head', 'rsd_link');
remove_action('wp_head', 'wlwmanifest_link');
remove_action('wp_head', 'wp_generator');
remove_action('wp_head', 'start_post_rel_link');
remove_action('wp_head', 'index_rel_link');
remove_action('wp_head', 'adjacent_posts_rel_link');

// Отключаем  REST API
add_filter('rest_enabled', '__return_false');

// Отключаем фильтры REST API
remove_action( 'xmlrpc_rsd_apis',            'rest_output_rsd' );
remove_action( 'wp_head',                    'rest_output_link_wp_head', 10, 0 );
remove_action( 'template_redirect',          'rest_output_link_header', 11, 0 );
remove_action( 'auth_cookie_malformed',      'rest_cookie_collect_status' );
remove_action( 'auth_cookie_expired',        'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_username',   'rest_cookie_collect_status' );
remove_action( 'auth_cookie_bad_hash',       'rest_cookie_collect_status' );
remove_action( 'auth_cookie_valid',          'rest_cookie_collect_status' );
remove_filter( 'rest_authentication_errors', 'rest_cookie_check_errors', 100 );

// Отключаем события REST API
remove_action( 'init',        'rest_api_init' );
remove_action( 'rest_api_init', 'rest_api_default_filters', 10, 1 );
remove_action( 'parse_request', 'rest_api_loaded' );

// Отключаем Embeds связанные с REST API
remove_action( 'rest_api_init',     'wp_oembed_register_route'              );
remove_filter( 'rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4 );

remove_action( 'wp_head', 'wp_oembed_add_discovery_links' );
// если собираетесь выводить вставки из других сайтов на своем, то закомментируйте след. строку.
remove_action( 'wp_head',     'wp_oembed_add_host_js'                 );


 // убираем с сайта эти идиотские emoje
remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

***************************************************************************************************************************
// создаем шаблон для определеного поста по категориям
define(SINGLE_PATH, TEMPLATEPATH . '/single');
add_filter('single_template', 'my_single_template');
function my_single_template($single) {
   global $wp_query, $post;

   foreach((array)get_the_category() as $cat) :

      if(file_exists(SINGLE_PATH . '/single-cat-' . $cat->slug . '.php'))
      return SINGLE_PATH . '/single-cat-' . $cat->slug . '.php';

      elseif(file_exists(SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php'))
      return SINGLE_PATH . '/single-cat-' . $cat->term_id . '.php';

     endforeach;
     return $single;
}



Комментариев нет:

Отправить комментарий