WordPress подключение файла стилей к постам с определенным шаблоном

Последнее обновление: 21 апреля, 2021

wordpress

 

 

 

Игорь Хыжняк, [21.04.21 09:42]
function styles() {
  if (is_front_page() ) {
    wp_enqueue_style( 'home-style', THEME_DIR . '/assets/css/home.css' );
  }
  if ( !is_front_page() ) {
        global $post;
        $template = ($post) ? explode("/", get_post_meta( $post->ID, '_wp_page_template', true )) : false;
        $template = (isset($template[1])) ? $template[1] : $template[0];
        if (in_array($template, array('testimonials.php')))
    wp_enqueue_style( 'testimonials-style', THEME_DIR . '/assets/css/testimonials.css' );
        if (in_array($template, array('list.php')))
    wp_enqueue_style( 'list-style', THEME_DIR . '/assets/css/list.css' );
        if (in_array($template, array('title.php')))
    wp_enqueue_style( 'title-style', THEME_DIR . '/assets/css/title.css' );
        if (in_array($template, array('content-text.php')))
    wp_enqueue_style( 'content-text-style', THEME_DIR . '/assets/css/content-text.css' );
        if (in_array($template, array('big-image.php')))
    wp_enqueue_style( 'big-image-style', THEME_DIR . '/assets/css/big-image.css' );
        if (in_array($template, array('image.php')))
    wp_enqueue_style( 'image-style', THEME_DIR . '/assets/css/image.css' );
        if (in_array($template, array('video.php')))
        wp_enqueue_style( 'video-style', THEME_DIR . '/assets/css/video.css' );
        if (in_array($template, array('graph.php')))
        wp_enqueue_style( 'graph-style', THEME_DIR . '/assets/css/graph.css' );
        if (in_array($template, array('table.php')))
        wp_enqueue_style( 'table-style', THEME_DIR . '/assets/css/table.css' );
        if (in_array($template, array('devices.php')))
        wp_enqueue_style( 'devices-style', THEME_DIR . '/assets/css/devices.css' );
        if (in_array($template, array('logos-slider.php')))
        wp_enqueue_style( 'logos-slider-style', THEME_DIR . '/assets/css/logos-slider.css' );
        if (in_array($template, array('impact-delivered.php')))
        wp_enqueue_style( 'impact-delivered-style', THEME_DIR . '/assets/css/impact-delivered.css' );
        if (in_array($template, array('hot-today.php')))
        wp_enqueue_style( 'hot-today-style', THEME_DIR . '/assets/css/hot-today.css' );
        if (in_array($template, array('case-studies.php')))
        wp_enqueue_style( 'case-studies-style', THEME_DIR . '/assets/css/case-studies.css' );
        if (in_array($template, array('case-studies-section.php')))
        wp_enqueue_style( 'case-studies-section-style', THEME_DIR . '/assets/css/case-studies-section.css' );

        // Services
        if (in_array($template, array('how-build.php')))
        wp_enqueue_style( 'how-build-style', THEME_DIR . '/assets/css/how-build.css' );
        if (in_array($template, array('text-and-scheme.php')))
        wp_enqueue_style( 'text-and-scheme-style', THEME_DIR . '/assets/css/text-and-scheme.css' );
        if (in_array($template, array('predictive-software-engineering.php')))
        wp_enqueue_style( 'predictive-software-engineering-style', THEME_DIR . '/assets/css/predictive-software-engineering.css' );
        if (in_array($template, array('graph-and-list.php')))
        wp_enqueue_style( 'graph-and-list-style', THEME_DIR . '/assets/css/graph-and-list.css' );
        if (in_array($template, array('flags.php')))
        wp_enqueue_style( 'flags-style', THEME_DIR . '/assets/css/flags.css' );
        if (in_array($template, array('list-grid.php')))
        wp_enqueue_style( 'list-grid-style', THEME_DIR . '/assets/css/list-grid.css' );
        if (in_array($template, array('scheme-line.php')))
        wp_enqueue_style( 'scheme-line-style', THEME_DIR . '/assets/css/scheme-line.css' );

Игорь Хыжняк, [21.04.21 09:42]
// Industries
        if (in_array($template, array('blocks-info.php')))
        wp_enqueue_style( 'blocks-info-style', THEME_DIR . '/assets/css/blocks-info.css' );
        if (in_array($template, array('radial-description.php')))
        wp_enqueue_style( 'radial-description-style', THEME_DIR . '/assets/css/radial-description.css' );
        if (in_array($template, array('title-list-step-line.php')))
        wp_enqueue_style( 'title-list-step-line-style', THEME_DIR . '/assets/css/title-list-step-line.css' );
        if (in_array($template, array('block-columns.php')))
        wp_enqueue_style( 'block-columns-style', THEME_DIR . '/assets/css/block-columns.css' );

        // Solutions
        if (in_array($template, array('block-scheme-description.php')))
        wp_enqueue_style( 'block-scheme-description-style', THEME_DIR . '/assets/css/block-scheme-description.css' );
        if (in_array($template, array('content-side-image.php')))
        wp_enqueue_style( 'content-side-image-style', THEME_DIR . '/assets/css/content-side-image.css' );

        // Carries
        if (in_array($template, array('text-on-image.php')))
            wp_enqueue_style( 'text-on-image-style', THEME_DIR . '/assets/css/text-on-image.css' );

        // Company
        if (in_array($template, array('management-team.php')))
            wp_enqueue_style( 'management-team-style', THEME_DIR . '/assets/css/management-team.css' );
        if (in_array($template, array('locations-contact.php')))
            wp_enqueue_style( 'locations-contact-style', THEME_DIR . '/assets/css/locations-contact.css' );

        // Insights
        if (in_array($template, array('blog-and-news.php')))
        wp_enqueue_style( 'blog-and-news-style', THEME_DIR . '/assets/css/blog-and-news.css' );
        if (in_array($template, array('blocks-star.php')))
        wp_enqueue_style( 'blocks-star-style', THEME_DIR . '/assets/css/blocks-star.css' );
        if (in_array($template, array('list-scroll.php')))
        wp_enqueue_style( 'list-scroll-style', THEME_DIR . '/assets/css/list-scroll.css' );

        // Methodologies
        if (in_array($template, array('scheme-and-list.php')))
        wp_enqueue_style( 'scheme-and-list-style', THEME_DIR . '/assets/css/scheme-and-list.css' );
        if (in_array($template, array('scheme-step.php')))
        wp_enqueue_style( 'scheme-step-style', THEME_DIR . '/assets/css/scheme-step.css' );
        if (in_array($template, array('technologies-set.php')))
        wp_enqueue_style( 'technologies-set-style', THEME_DIR . '/assets/css/technologies-set.css' );
        if (in_array($template, array('scheme-model.php')))
        wp_enqueue_style( 'scheme-model-style', THEME_DIR . '/assets/css/scheme-model.css' );
        if (in_array($template, array('icon-description.php')))
        wp_enqueue_style( 'icon-description-style', THEME_DIR . '/assets/css/icon-description.css' );
        if (in_array($template, array('image-description.php')))
        wp_enqueue_style( 'image-description-style', THEME_DIR . '/assets/css/image-description.css' );

        // Competences
        if (in_array($template, array('text-image-list.php')))
        wp_enqueue_style( 'text-image-list-style', THEME_DIR . '/assets/css/text-image-list.css' );

Игорь Хыжняк, [21.04.21 09:42]
wp_enqueue_style( 'placeholder-style', THEME_DIR . '/assets/css/placeholder.css' );
        //if (in_array($template, array('custom-software-development.php','lets-talk.php','privacy-policy.php','page-placeholder-csd.php')))
    wp_enqueue_style( 'csd-style', THEME_DIR . '/assets/css/csd.css' );
    wp_enqueue_style( 'industries-style', THEME_DIR . '/assets/css/industries.css' );
    wp_enqueue_style( 'case-study-single-page-style', THEME_DIR . '/assets/css/case-study-single-page.css' );
    wp_enqueue_style( 'competences-style', THEME_DIR . '/assets/css/competences.css' );
    wp_enqueue_style( 'solutions-style', THEME_DIR . '/assets/css/solutions.css' );
  }
  wp_enqueue_style( 'error-style', THEME_DIR . '/assets/css/error.css' );
  wp_enqueue_style( 'fancybox-style', THEME_DIR . '/assets/css/jquery.fancybox.css' );
    //if (in_array($template, array('services-page.php')) || is_front_page())
  wp_enqueue_style( 'services-style', THEME_DIR . '/assets/css/services.css' );

  wp_enqueue_style( 'main-style', THEME_DIR . '/assets/css/main.css' );

  //wp_enqueue_style('slick-style', 'https://cdn.jsdelivr.net/npm/slick-carousel@1.8.1/slick/slick.css');
  wp_enqueue_style('slick-style', THEME_DIR .  '/assets/css/slick.css');
  if ( is_page_template('page-example.php'))
    wp_enqueue_style( 'example', THEME_DIR .  '/assets/css/example.css' );

}
add_action( 'wp_head', 'styles', -999 );